<!DOCTYPE html>

<html>
<head>
  <title>soundmanager2.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="soundmanager2.html">
                soundmanager2.js
              </a>
            
              
              <a class="source" href="SoundManager2_AS.html">
                SoundManager2_AS.as
              </a>
            
              
              <a class="source" href="SoundManager2_AS3.html">
                SoundManager2_AS3.as
              </a>
            
              
              <a class="source" href="SoundManager2_SMSound_AS3.html">
                SoundManager2_SMSound_AS3.as
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>soundmanager2.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              
            </div>
            
            <div class="content"><div class='highlight'><pre><span class="comment">/** @license
 *
 * SoundManager 2: JavaScript Sound for the Web
 * ----------------------------------------------
 * http://schillmania.com/projects/soundmanager2/
 *
 * Copyright (c) 2007, Scott Schiller. All rights reserved.
 * Code provided under the BSD License:
 * http://schillmania.com/projects/soundmanager2/license.txt
 *
 * V2.97a.20170601
 */</span>

<span class="comment">/**
 * About this file
 * -------------------------------------------------------------------------------------
 * This is the fully-commented source version of the SoundManager 2 API,
 * recommended for use during development and testing.
 *
 * See soundmanager2-nodebug-jsmin.js for an optimized build (~11KB with gzip.)
 * http://schillmania.com/projects/soundmanager2/doc/getstarted/#basic-inclusion
 * Alternately, serve this file with gzip for 75% compression savings (~30KB over HTTP.)
 *
 * You may notice &lt;d&gt; and &lt;/d&gt; comments in this source; these are delimiters for
 * debug blocks which are removed in the -nodebug builds, further optimizing code size.
 *
 * Also, as you may note: Whoa, reliable cross-platform/device audio support is hard! ;)
 */</span>

(<span class="function"><span class="keyword">function</span> <span class="title">SM2</span><span class="params">(window, _undefined)</span> {</span>

<span class="comment">/* global Audio, document, window, navigator, define, module, SM2_DEFER, opera, setTimeout, setInterval, clearTimeout, sm2Debugger */</span>

<span class="string">'use strict'</span>;

<span class="keyword">if</span> (!window || !window.document) {</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <p>Don&#39;t cross the [environment] streams. SM2 expects to be running in a browser, not under node.js etc.
Additionally, if a browser somehow manages to fail this test, as Egon said: &quot;It would be bad.&quot;</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'SoundManager requires a browser with window and document objects.'</span>);

}

<span class="keyword">var</span> soundManager = <span class="literal">null</span>;

<span class="comment">/**
 * The SoundManager constructor.
 *
 * @constructor
 * @param {string} smURL Optional: Path to SWF files
 * @param {string} smID Optional: The ID to use for the SWF container element
 * @this {SoundManager}
 * @return {SoundManager} The new SoundManager instance
 */</span>

<span class="function"><span class="keyword">function</span> <span class="title">SoundManager</span><span class="params">(smURL, smID)</span> {</span>

  <span class="comment">/**
   * soundManager configuration options list
   * defines top-level configuration properties to be applied to the soundManager instance (eg. soundManager.flashVersion)
   * to set these properties, use the setup() method - eg., soundManager.setup({url: '/swf/', flashVersion: 9})
   */</span>

  <span class="keyword">this</span>.setupOptions = {

    url: (smURL || <span class="literal">null</span>),             <span class="comment">// path (directory) where SoundManager 2 SWFs exist, eg., /path/to/swfs/</span>
    flashVersion: <span class="number">8</span>,                  <span class="comment">// flash build to use (8 or 9.) Some API features require 9.</span>
    debugMode: <span class="literal">true</span>,                  <span class="comment">// enable debugging output (console.log() with HTML fallback)</span>
    debugFlash: <span class="literal">false</span>,                <span class="comment">// enable debugging output inside SWF, troubleshoot Flash/browser issues</span>
    useConsole: <span class="literal">true</span>,                 <span class="comment">// use console.log() if available (otherwise, writes to #soundmanager-debug element)</span>
    consoleOnly: <span class="literal">true</span>,                <span class="comment">// if console is being used, do not create/write to #soundmanager-debug</span>
    waitForWindowLoad: <span class="literal">false</span>,         <span class="comment">// force SM2 to wait for window.onload() before trying to call soundManager.onload()</span>
    bgColor: <span class="string">'#ffffff'</span>,               <span class="comment">// SWF background color. N/A when wmode = 'transparent'</span>
    useHighPerformance: <span class="literal">false</span>,        <span class="comment">// position:fixed flash movie can help increase js/flash speed, minimize lag</span>
    flashPollingInterval: <span class="literal">null</span>,       <span class="comment">// msec affecting whileplaying/loading callback frequency. If null, default of 50 msec is used.</span>
    html5PollingInterval: <span class="literal">null</span>,       <span class="comment">// msec affecting whileplaying() for HTML5 audio, excluding mobile devices. If null, native HTML5 update events are used.</span>
    flashLoadTimeout: <span class="number">1000</span>,           <span class="comment">// msec to wait for flash movie to load before failing (0 = infinity)</span>
    wmode: <span class="literal">null</span>,                      <span class="comment">// flash rendering mode - null, 'transparent', or 'opaque' (last two allow z-index to work)</span>
    allowScriptAccess: <span class="string">'always'</span>,      <span class="comment">// for scripting the SWF (object/embed property), 'always' or 'sameDomain'</span>
    useFlashBlock: <span class="literal">false</span>,             <span class="comment">// *requires flashblock.css, see demos* - allow recovery from flash blockers. Wait indefinitely and apply timeout CSS to SWF, if applicable.</span>
    useHTML5Audio: <span class="literal">true</span>,              <span class="comment">// use HTML5 Audio() where API is supported (most Safari, Chrome versions), Firefox (MP3/MP4 support varies.) Ideally, transparent vs. Flash API where possible.</span>
    forceUseGlobalHTML5Audio: <span class="literal">false</span>,  <span class="comment">// if true, a single Audio() object is used for all sounds - and only one can play at a time.</span>
    ignoreMobileRestrictions: <span class="literal">false</span>,  <span class="comment">// if true, SM2 will not apply global HTML5 audio rules to mobile UAs. iOS &gt; 7 and WebViews may allow multiple Audio() instances.</span>
    html5Test: <span class="regexp">/^(probably|maybe)$/i</span>, <span class="comment">// HTML5 Audio() format support test. Use /^probably$/i; if you want to be more conservative.</span>
    preferFlash: <span class="literal">false</span>,               <span class="comment">// overrides useHTML5audio, will use Flash for MP3/MP4/AAC if present. Potential option if HTML5 playback with these formats is quirky.</span>
    noSWFCache: <span class="literal">false</span>,                <span class="comment">// if true, appends ?ts={date} to break aggressive SWF caching.</span>
    idPrefix: <span class="string">'sound'</span>                 <span class="comment">// if an id is not provided to createSound(), this prefix is used for generated IDs - 'sound0', 'sound1' etc.</span>

  };

  <span class="keyword">this</span>.defaultOptions = {

    <span class="comment">/**
     * the default configuration for sound objects made with createSound() and related methods
     * eg., volume, auto-load behaviour and so forth
     */</span>

    autoLoad: <span class="literal">false</span>,        <span class="comment">// enable automatic loading (otherwise .load() will be called on demand with .play(), the latter being nicer on bandwidth - if you want to .load yourself, you also can)</span>
    autoPlay: <span class="literal">false</span>,        <span class="comment">// enable playing of file as soon as possible (much faster if "stream" is true)</span>
    from: <span class="literal">null</span>,             <span class="comment">// position to start playback within a sound (msec), default = beginning</span>
    loops: <span class="number">1</span>,               <span class="comment">// how many times to repeat the sound (position will wrap around to 0, setPosition() will break out of loop when &gt;0)</span>
    onid3: <span class="literal">null</span>,            <span class="comment">// callback function for "ID3 data is added/available"</span>
    onerror: <span class="literal">null</span>,          <span class="comment">// callback function for "load failed" (or, playback/network/decode error under HTML5.)</span>
    onload: <span class="literal">null</span>,           <span class="comment">// callback function for "load finished"</span>
    whileloading: <span class="literal">null</span>,     <span class="comment">// callback function for "download progress update" (X of Y bytes received)</span>
    onplay: <span class="literal">null</span>,           <span class="comment">// callback for "play" start</span>
    onpause: <span class="literal">null</span>,          <span class="comment">// callback for "pause"</span>
    onresume: <span class="literal">null</span>,         <span class="comment">// callback for "resume" (pause toggle)</span>
    whileplaying: <span class="literal">null</span>,     <span class="comment">// callback during play (position update)</span>
    onposition: <span class="literal">null</span>,       <span class="comment">// object containing times and function callbacks for positions of interest</span>
    onstop: <span class="literal">null</span>,           <span class="comment">// callback for "user stop"</span>
    onfinish: <span class="literal">null</span>,         <span class="comment">// callback function for "sound finished playing"</span>
    multiShot: <span class="literal">true</span>,        <span class="comment">// let sounds "restart" or layer on top of each other when played multiple times, rather than one-shot/one at a time</span>
    multiShotEvents: <span class="literal">false</span>, <span class="comment">// fire multiple sound events (currently onfinish() only) when multiShot is enabled</span>
    position: <span class="literal">null</span>,         <span class="comment">// offset (milliseconds) to seek to within loaded sound data.</span>
    pan: <span class="number">0</span>,                 <span class="comment">// "pan" settings, left-to-right, -100 to 100</span>
    playbackRate: <span class="number">1</span>,        <span class="comment">// rate at which to play the sound (HTML5-only)</span>
    stream: <span class="literal">true</span>,           <span class="comment">// allows playing before entire file has loaded (recommended)</span>
    to: <span class="literal">null</span>,               <span class="comment">// position to end playback within a sound (msec), default = end</span>
    type: <span class="literal">null</span>,             <span class="comment">// MIME-like hint for file pattern / canPlay() tests, eg. audio/mp3</span>
    usePolicyFile: <span class="literal">false</span>,   <span class="comment">// enable crossdomain.xml request for audio on remote domains (for ID3/waveform access)</span>
    volume: <span class="number">100</span>             <span class="comment">// self-explanatory. 0-100, the latter being the max.</span>

  };

  <span class="keyword">this</span>.flash9Options = {

    <span class="comment">/**
     * flash 9-only options,
     * merged into defaultOptions if flash 9 is being used
     */</span>

    onfailure: <span class="literal">null</span>,        <span class="comment">// callback function for when playing fails (Flash 9, MovieStar + RTMP-only)</span>
    isMovieStar: <span class="literal">null</span>,      <span class="comment">// "MovieStar" MPEG4 audio mode. Null (default) = auto detect MP4, AAC etc. based on URL. true = force on, ignore URL</span>
    usePeakData: <span class="literal">false</span>,     <span class="comment">// enable left/right channel peak (level) data</span>
    useWaveformData: <span class="literal">false</span>, <span class="comment">// enable sound spectrum (raw waveform data) - NOTE: May increase CPU load.</span>
    useEQData: <span class="literal">false</span>,       <span class="comment">// enable sound EQ (frequency spectrum data) - NOTE: May increase CPU load.</span>
    onbufferchange: <span class="literal">null</span>,   <span class="comment">// callback for "isBuffering" property change</span>
    ondataerror: <span class="literal">null</span>       <span class="comment">// callback for waveform/eq data access error (flash playing audio in other tabs/domains)</span>

  };

  <span class="keyword">this</span>.movieStarOptions = {

    <span class="comment">/**
     * flash 9.0r115+ MPEG4 audio options,
     * merged into defaultOptions if flash 9+movieStar mode is enabled
     */</span>

    bufferTime: <span class="number">3</span>,          <span class="comment">// seconds of data to buffer before playback begins (null = flash default of 0.1 seconds - if AAC playback is gappy, try increasing.)</span>
    serverURL: <span class="literal">null</span>,        <span class="comment">// rtmp: FMS or FMIS server to connect to, required when requesting media via RTMP or one of its variants</span>
    onconnect: <span class="literal">null</span>,        <span class="comment">// rtmp: callback for connection to flash media server</span>
    duration: <span class="literal">null</span>          <span class="comment">// rtmp: song duration (msec)</span>

  };

  <span class="keyword">this</span>.audioFormats = {

    <span class="comment">/**
     * determines HTML5 support + flash requirements.
     * if no support (via flash and/or HTML5) for a "required" format, SM2 will fail to start.
     * flash fallback is used for MP3 or MP4 if HTML5 can't play it (or if preferFlash = true)
     */</span>

    mp3: {
      type: [<span class="string">'audio/mpeg; codecs="mp3"'</span>, <span class="string">'audio/mpeg'</span>, <span class="string">'audio/mp3'</span>, <span class="string">'audio/MPA'</span>, <span class="string">'audio/mpa-robust'</span>],
      required: <span class="literal">true</span>
    },

    mp4: {
      related: [<span class="string">'aac'</span>, <span class="string">'m4a'</span>, <span class="string">'m4b'</span>], <span class="comment">// additional formats under the MP4 container</span>
      type: [<span class="string">'audio/mp4; codecs="mp4a.40.2"'</span>, <span class="string">'audio/aac'</span>, <span class="string">'audio/x-m4a'</span>, <span class="string">'audio/MP4A-LATM'</span>, <span class="string">'audio/mpeg4-generic'</span>],
      required: <span class="literal">false</span>
    },

    ogg: {
      type: [<span class="string">'audio/ogg; codecs=vorbis'</span>],
      required: <span class="literal">false</span>
    },

    opus: {
      type: [<span class="string">'audio/ogg; codecs=opus'</span>, <span class="string">'audio/opus'</span>],
      required: <span class="literal">false</span>
    },

    wav: {
      type: [<span class="string">'audio/wav; codecs="1"'</span>, <span class="string">'audio/wav'</span>, <span class="string">'audio/wave'</span>, <span class="string">'audio/x-wav'</span>],
      required: <span class="literal">false</span>
    },

    flac: {
      type: [<span class="string">'audio/flac'</span>],
      required: <span class="literal">false</span>
    }

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <p>HTML attributes (id + class names) for the SWF container</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  <span class="keyword">this</span>.movieID = <span class="string">'sm2-container'</span>;
  <span class="keyword">this</span>.id = (smID || <span class="string">'sm2movie'</span>);

  <span class="keyword">this</span>.debugID = <span class="string">'soundmanager-debug'</span>;
  <span class="keyword">this</span>.debugURLParam = <span class="regexp">/([#?&amp;])debug=1/i</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <p>dynamic attributes</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  <span class="keyword">this</span>.versionNumber = <span class="string">'V2.97a.20170601'</span>;
  <span class="keyword">this</span>.version = <span class="literal">null</span>;
  <span class="keyword">this</span>.movieURL = <span class="literal">null</span>;
  <span class="keyword">this</span>.altURL = <span class="literal">null</span>;
  <span class="keyword">this</span>.swfLoaded = <span class="literal">false</span>;
  <span class="keyword">this</span>.enabled = <span class="literal">false</span>;
  <span class="keyword">this</span>.oMC = <span class="literal">null</span>;
  <span class="keyword">this</span>.sounds = {};
  <span class="keyword">this</span>.soundIDs = [];
  <span class="keyword">this</span>.muted = <span class="literal">false</span>;
  <span class="keyword">this</span>.didFlashBlock = <span class="literal">false</span>;
  <span class="keyword">this</span>.filePattern = <span class="literal">null</span>;

  <span class="keyword">this</span>.filePatterns = {
    flash8: <span class="regexp">/\.mp3(\?.*)?$/i</span>,
    flash9: <span class="regexp">/\.mp3(\?.*)?$/i</span>
  };</pre></div></div>
            
        </li>
        
        
        <li id="section-5">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-5">&#182;</a>
              </div>
              <p>support indicators, set at init</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  <span class="keyword">this</span>.features = {
    buffering: <span class="literal">false</span>,
    peakData: <span class="literal">false</span>,
    waveformData: <span class="literal">false</span>,
    eqData: <span class="literal">false</span>,
    movieStar: <span class="literal">false</span>
  };</pre></div></div>
            
        </li>
        
        
        <li id="section-6">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-6">&#182;</a>
              </div>
              <p>flash sandbox info, used primarily in troubleshooting</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  <span class="keyword">this</span>.sandbox = {</pre></div></div>
            
        </li>
        
        
        <li id="section-7">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-7">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    type: <span class="literal">null</span>,
    types: {
      remote: <span class="string">'remote (domain-based) rules'</span>,
      localWithFile: <span class="string">'local with file access (no internet access)'</span>,
      localWithNetwork: <span class="string">'local with network (internet access only, no local access)'</span>,
      localTrusted: <span class="string">'local, trusted (local+internet access)'</span>
    },
    description: <span class="literal">null</span>,
    noRemote: <span class="literal">null</span>,
    noLocal: <span class="literal">null</span></pre></div></div>
            
        </li>
        
        
        <li id="section-8">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-8">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  };

  <span class="comment">/**
   * format support (html5/flash)
   * stores canPlayType() results based on audioFormats.
   * eg. { mp3: boolean, mp4: boolean }
   * treat as read-only.
   */</span>

  <span class="keyword">this</span>.html5 = {
    usingFlash: <span class="literal">null</span> <span class="comment">// set if/when flash fallback is needed</span>
  };</pre></div></div>
            
        </li>
        
        
        <li id="section-9">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-9">&#182;</a>
              </div>
              <p>file type support hash</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>.flash = {};</pre></div></div>
            
        </li>
        
        
        <li id="section-10">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-10">&#182;</a>
              </div>
              <p>determined at init time</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>.html5Only = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-11">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-11">&#182;</a>
              </div>
              <p>used for special cases (eg. iPad/iPhone/palm OS?)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>.ignoreFlash = <span class="literal">false</span>;

  <span class="comment">/**
   * a few private internals (OK, a lot. :D)
   */</span>

  <span class="keyword">var</span> SMSound,
  sm2 = <span class="keyword">this</span>, globalHTML5Audio = <span class="literal">null</span>, flash = <span class="literal">null</span>, sm = <span class="string">'soundManager'</span>, smc = sm + <span class="string">': '</span>, h5 = <span class="string">'HTML5::'</span>, id, ua = navigator.userAgent, wl = window.location.href.toString(), doc = document, doNothing, setProperties, init, fV, on_queue = [], debugOpen = <span class="literal">true</span>, debugTS, didAppend = <span class="literal">false</span>, appendSuccess = <span class="literal">false</span>, didInit = <span class="literal">false</span>, disabled = <span class="literal">false</span>, windowLoaded = <span class="literal">false</span>, _wDS, wdCount = <span class="number">0</span>, initComplete, mixin, assign, extraOptions, addOnEvent, processOnEvents, initUserOnload, delayWaitForEI, waitForEI, rebootIntoHTML5, setVersionInfo, handleFocus, strings, initMovie, domContentLoaded, winOnLoad, didDCLoaded, getDocument, createMovie, catchError, setPolling, initDebug, debugLevels = [<span class="string">'log'</span>, <span class="string">'info'</span>, <span class="string">'warn'</span>, <span class="string">'error'</span>], defaultFlashVersion = <span class="number">8</span>, disableObject, failSafely, normalizeMovieURL, oRemoved = <span class="literal">null</span>, oRemovedHTML = <span class="literal">null</span>, str, flashBlockHandler, getSWFCSS, swfCSS, toggleDebug, loopFix, policyFix, complain, idCheck, waitingForEI = <span class="literal">false</span>, initPending = <span class="literal">false</span>, startTimer, stopTimer, timerExecute, h5TimerCount = <span class="number">0</span>, h5IntervalTimer = <span class="literal">null</span>, parseURL, messages = [],
  canIgnoreFlash, needsFlash = <span class="literal">null</span>, featureCheck, html5OK, html5CanPlay, html5ErrorCodes, html5Ext, html5Unload, domContentLoadedIE, testHTML5, event, slice = Array.prototype.slice, useGlobalHTML5Audio = <span class="literal">false</span>, lastGlobalHTML5URL, hasFlash, detectFlash, badSafariFix, html5_events, showSupport, flushMessages, wrapCallback, idCounter = <span class="number">0</span>, didSetup, msecScale = <span class="number">1000</span>,
  is_iDevice = ua.match(<span class="regexp">/(ipad|iphone|ipod)/i</span>), isAndroid = ua.match(<span class="regexp">/android/i</span>), isIE = ua.match(<span class="regexp">/msie|trident/i</span>),
  isWebkit = ua.match(<span class="regexp">/webkit/i</span>),
  isSafari = (ua.match(<span class="regexp">/safari/i</span>) &amp;&amp; !ua.match(<span class="regexp">/chrome/i</span>)),
  isOpera = (ua.match(<span class="regexp">/opera/i</span>)),
  mobileHTML5 = (ua.match(<span class="regexp">/(mobile|pre\/|xoom)/i</span>) || is_iDevice || isAndroid),
  isBadSafari = (!wl.match(<span class="regexp">/usehtml5audio/i</span>) &amp;&amp; !wl.match(<span class="regexp">/sm2-ignorebadua/i</span>) &amp;&amp; isSafari &amp;&amp; !ua.match(<span class="regexp">/silk/i</span>) &amp;&amp; ua.match(<span class="regexp">/OS\sX\s10_6_([3-7])/i</span>)), <span class="comment">// Safari 4 and 5 (excluding Kindle Fire, "Silk") occasionally fail to load/play HTML5 audio on Snow Leopard 10.6.3 through 10.6.7 due to bug(s) in QuickTime X and/or other underlying frameworks. :/ Confirmed bug. https://bugs.webkit.org/show_bug.cgi?id=32159</span>
  hasConsole = (window.console !== _<span class="literal">undefined</span> &amp;&amp; console.log !== _<span class="literal">undefined</span>),
  isFocused = (doc.hasFocus !== _<span class="literal">undefined</span> ? doc.hasFocus() : <span class="literal">null</span>),
  tryInitOnFocus = (isSafari &amp;&amp; (doc.hasFocus === _<span class="literal">undefined</span> || !doc.hasFocus())),
  okToDisable = !tryInitOnFocus,
  flashMIME = <span class="regexp">/(mp3|mp4|mpa|m4a|m4b)/i</span>,
  emptyURL = <span class="string">'about:blank'</span>, <span class="comment">// safe URL to unload, or load nothing from (flash 8 + most HTML5 UAs)</span>
  emptyWAV = <span class="string">'data:audio/wave;base64,/UklGRiYAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQIAAAD//w=='</span>, <span class="comment">// tiny WAV for HTML5 unloading</span>
  overHTTP = (doc.location ? doc.location.protocol.match(<span class="regexp">/http/i</span>) : <span class="literal">null</span>),
  http = (!overHTTP ? <span class="string">'//'</span> : <span class="string">''</span>),</pre></div></div>
            
        </li>
        
        
        <li id="section-12">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-12">&#182;</a>
              </div>
              <p>mp3, mp4, aac etc.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  netStreamMimeTypes = <span class="regexp">/^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4|m4v|m4a|m4b|mp4v|3gp|3g2)\s*(?:$|;)/i</span>,</pre></div></div>
            
        </li>
        
        
        <li id="section-13">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-13">&#182;</a>
              </div>
              <p>Flash v9.0r115+ &quot;moviestar&quot; formats</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  netStreamTypes = [<span class="string">'mpeg4'</span>, <span class="string">'aac'</span>, <span class="string">'flv'</span>, <span class="string">'mov'</span>, <span class="string">'mp4'</span>, <span class="string">'m4v'</span>, <span class="string">'f4v'</span>, <span class="string">'m4a'</span>, <span class="string">'m4b'</span>, <span class="string">'mp4v'</span>, <span class="string">'3gp'</span>, <span class="string">'3g2'</span>],
  netStreamPattern = <span class="keyword">new</span> RegExp(<span class="string">'\\.('</span> + netStreamTypes.join(<span class="string">'|'</span>) + <span class="string">')(\\?.*)?$'</span>, <span class="string">'i'</span>);

  <span class="keyword">this</span>.mimePattern = <span class="regexp">/^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i</span>; <span class="comment">// default mp3 set</span></pre></div></div>
            
        </li>
        
        
        <li id="section-14">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-14">&#182;</a>
              </div>
              <p>use altURL if not &quot;online&quot;</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>.useAltURL = !overHTTP;

  swfCSS = {
    swfBox: <span class="string">'sm2-object-box'</span>,
    swfDefault: <span class="string">'movieContainer'</span>,
    swfError: <span class="string">'swf_error'</span>, <span class="comment">// SWF loaded, but SM2 couldn't start (other error)</span>
    swfTimedout: <span class="string">'swf_timedout'</span>,
    swfLoaded: <span class="string">'swf_loaded'</span>,
    swfUnblocked: <span class="string">'swf_unblocked'</span>, <span class="comment">// or loaded OK</span>
    sm2Debug: <span class="string">'sm2_debug'</span>,
    highPerf: <span class="string">'high_performance'</span>,
    flashDebug: <span class="string">'flash_debug'</span>
  };

  <span class="comment">/**
   * HTML5 error codes, per W3C
   * Error code 1, MEDIA_ERR_ABORTED: Client aborted download at user's request.
   * Error code 2, MEDIA_ERR_NETWORK: A network error of some description caused the user agent to stop fetching the media resource, after the resource was established to be usable.
   * Error code 3, MEDIA_ERR_DECODE: An error of some description occurred while decoding the media resource, after the resource was established to be usable.
   * Error code 4, MEDIA_ERR_SRC_NOT_SUPPORTED: Media (audio file) not supported ("not usable.")
   * Reference: https://html.spec.whatwg.org/multipage/embedded-content.html#error-codes
   */</span>
  html5ErrorCodes = [
    <span class="literal">null</span>,
    <span class="string">'MEDIA_ERR_ABORTED'</span>,
    <span class="string">'MEDIA_ERR_NETWORK'</span>,
    <span class="string">'MEDIA_ERR_DECODE'</span>,
    <span class="string">'MEDIA_ERR_SRC_NOT_SUPPORTED'</span>
  ];

  <span class="comment">/**
   * basic HTML5 Audio() support test
   * try...catch because of IE 9 "not implemented" nonsense
   * https://github.com/Modernizr/Modernizr/issues/224
   */</span>

  <span class="keyword">this</span>.hasHTML5 = (<span class="keyword">function</span>() {
    <span class="keyword">try</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-15">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-15">&#182;</a>
              </div>
              <p>new Audio(null) for stupid Opera 9.64 case, which throws not_enough_arguments exception otherwise.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">return</span> (Audio !== _<span class="literal">undefined</span> &amp;&amp; (isOpera &amp;&amp; opera !== _<span class="literal">undefined</span> &amp;&amp; opera.version() &lt; <span class="number">10</span> ? <span class="keyword">new</span> Audio(<span class="literal">null</span>) : <span class="keyword">new</span> Audio()).canPlayType !== _<span class="literal">undefined</span>);
    } <span class="keyword">catch</span>(e) {
      <span class="keyword">return</span> <span class="literal">false</span>;
    }
  }());

  <span class="comment">/**
   * Public SoundManager API
   * -----------------------
   */</span>

  <span class="comment">/**
   * Configures top-level soundManager properties.
   *
   * @param {object} options Option parameters, eg. { flashVersion: 9, url: '/path/to/swfs/' }
   * onready and ontimeout are also accepted parameters. call soundManager.setup() to see the full list.
   */</span>

  <span class="keyword">this</span>.setup = <span class="keyword">function</span>(options) {

    <span class="keyword">var</span> noURL = (!sm2.url);</pre></div></div>
            
        </li>
        
        
        <li id="section-16">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-16">&#182;</a>
              </div>
              <p>warn if flash options have already been applied</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (options !== _<span class="literal">undefined</span> &amp;&amp; didInit &amp;&amp; needsFlash &amp;&amp; sm2.ok() &amp;&amp; (options.flashVersion !== _<span class="literal">undefined</span> || options.url !== _<span class="literal">undefined</span> || options.html5Test !== _<span class="literal">undefined</span>)) {
      complain(str(<span class="string">'setupLate'</span>));
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-17">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-17">&#182;</a>
              </div>
              <p>TODO: defer: true?</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    assign(options);

    <span class="keyword">if</span> (!useGlobalHTML5Audio) {

      <span class="keyword">if</span> (mobileHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-18">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-18">&#182;</a>
              </div>
              <p>force the singleton HTML5 pattern on mobile, by default.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (!sm2.setupOptions.ignoreMobileRestrictions || sm2.setupOptions.forceUseGlobalHTML5Audio) {
          messages.push(strings.globalHTML5);
          useGlobalHTML5Audio = <span class="literal">true</span>;
        }

      } <span class="keyword">else</span> <span class="keyword">if</span> (sm2.setupOptions.forceUseGlobalHTML5Audio) {</pre></div></div>
            
        </li>
        
        
        <li id="section-19">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-19">&#182;</a>
              </div>
              <p>only apply singleton HTML5 on desktop if forced.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        messages.push(strings.globalHTML5);
        useGlobalHTML5Audio = <span class="literal">true</span>;

      }

    }

    <span class="keyword">if</span> (!didSetup &amp;&amp; mobileHTML5) {

      <span class="keyword">if</span> (sm2.setupOptions.ignoreMobileRestrictions) {

        messages.push(strings.ignoreMobile);

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-20">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-20">&#182;</a>
              </div>
              <p>prefer HTML5 for mobile + tablet-like devices, probably more reliable vs. flash at this point.</p>

            </div>
            
        </li>
        
        
        <li id="section-21">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-21">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (!sm2.setupOptions.useHTML5Audio || sm2.setupOptions.preferFlash) {</pre></div></div>
            
        </li>
        
        
        <li id="section-22">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-22">&#182;</a>
              </div>
              <p>notify that defaults are being changed.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2._wD(strings.mobileUA);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-23">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-23">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        sm2.setupOptions.useHTML5Audio = <span class="literal">true</span>;
        sm2.setupOptions.preferFlash = <span class="literal">false</span>;

        <span class="keyword">if</span> (is_iDevice) {</pre></div></div>
            
        </li>
        
        
        <li id="section-24">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-24">&#182;</a>
              </div>
              <p>no flash here.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2.ignoreFlash = <span class="literal">true</span>;

        } <span class="keyword">else</span> <span class="keyword">if</span> ((isAndroid &amp;&amp; !ua.match(<span class="regexp">/android\s2\.3/i</span>)) || !isAndroid) {

          <span class="comment">/**
           * Android devices tend to work better with a single audio instance, specifically for chained playback of sounds in sequence.
           * Common use case: exiting sound onfinish() -&gt; createSound() -&gt; play()
           * Presuming similar restrictions for other mobile, non-Android, non-iOS devices.
           */</span></pre></div></div>
            
        </li>
        
        
        <li id="section-25">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-25">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2._wD(strings.globalHTML5);</pre></div></div>
            
        </li>
        
        
        <li id="section-26">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-26">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          useGlobalHTML5Audio = <span class="literal">true</span>;

        }

      }

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-27">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-27">&#182;</a>
              </div>
              <p>special case 1: &quot;Late setup&quot;. SM2 loaded normally, but user didn&#39;t assign flash URL eg., setup({url:...}) before SM2 init. Treat as delayed init.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (options) {

      <span class="keyword">if</span> (noURL &amp;&amp; didDCLoaded &amp;&amp; options.url !== _<span class="literal">undefined</span>) {
        sm2.beginDelayedInit();
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-28">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-28">&#182;</a>
              </div>
              <p>special case 2: If lazy-loading SM2 (DOMContentLoaded has already happened) and user calls setup() with url: parameter, try to init ASAP.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (!didDCLoaded &amp;&amp; options.url !== _<span class="literal">undefined</span> &amp;&amp; doc.readyState === <span class="string">'complete'</span>) {
        setTimeout(domContentLoaded, <span class="number">1</span>);
      }

    }

    didSetup = <span class="literal">true</span>;

    <span class="keyword">return</span> sm2;

  };

  <span class="keyword">this</span>.ok = <span class="keyword">function</span>() {

    <span class="keyword">return</span> (needsFlash ? (didInit &amp;&amp; !disabled) : (sm2.useHTML5Audio &amp;&amp; sm2.hasHTML5));

  };

  <span class="keyword">this</span>.supported = <span class="keyword">this</span>.ok; <span class="comment">// legacy</span>

  <span class="keyword">this</span>.getMovie = <span class="keyword">function</span>(movie_id) {</pre></div></div>
            
        </li>
        
        
        <li id="section-29">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-29">&#182;</a>
              </div>
              <p>safety net: some old browsers differ on SWF references, possibly related to ExternalInterface / flash version</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">return</span> id(movie_id) || doc[movie_id] || window[movie_id];

  };

  <span class="comment">/**
   * Creates a SMSound sound object instance. Can also be overloaded, e.g., createSound('mySound', '/some.mp3');
   *
   * @param {object} oOptions Sound options (at minimum, url parameter is required.)
   * @return {object} SMSound The new SMSound object.
   */</span>

  <span class="keyword">this</span>.createSound = <span class="keyword">function</span>(oOptions, _url) {

    <span class="keyword">var</span> cs, cs_string, options, oSound = <span class="literal">null</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-30">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-30">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    cs = sm + <span class="string">'.createSound(): '</span>;
    cs_string = cs + str(!didInit ? <span class="string">'notReady'</span> : <span class="string">'notOK'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-31">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-31">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (!didInit || !sm2.ok()) {
      complain(cs_string);
      <span class="keyword">return</span> <span class="literal">false</span>;
    }

    <span class="keyword">if</span> (_url !== _<span class="literal">undefined</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-32">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-32">&#182;</a>
              </div>
              <p>function overloading in JS! :) ... assume simple createSound(id, url) use case.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      oOptions = {
        id: oOptions,
        url: _url
      };
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-33">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-33">&#182;</a>
              </div>
              <p>inherit from defaultOptions</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    options = mixin(oOptions);

    options.url = parseURL(options.url);</pre></div></div>
            
        </li>
        
        
        <li id="section-34">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-34">&#182;</a>
              </div>
              <p>generate an id, if needed.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (options.id === _<span class="literal">undefined</span>) {
      options.id = sm2.setupOptions.idPrefix + (idCounter++);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-35">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-35">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (options.id.toString().charAt(<span class="number">0</span>).match(<span class="regexp">/^[0-9]$/</span>)) {
      sm2._wD(cs + str(<span class="string">'badID'</span>, options.id), <span class="number">2</span>);
    }

    sm2._wD(cs + options.id + (options.url ? <span class="string">' ('</span> + options.url + <span class="string">')'</span> : <span class="string">''</span>), <span class="number">1</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-36">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-36">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (idCheck(options.id, <span class="literal">true</span>)) {
      sm2._wD(cs + options.id + <span class="string">' exists'</span>, <span class="number">1</span>);
      <span class="keyword">return</span> sm2.sounds[options.id];
    }

    <span class="function"><span class="keyword">function</span> <span class="title">make</span><span class="params">()</span> {</span>

      options = loopFix(options);
      sm2.sounds[options.id] = <span class="keyword">new</span> SMSound(options);
      sm2.soundIDs.push(options.id);
      <span class="keyword">return</span> sm2.sounds[options.id];

    }

    <span class="keyword">if</span> (html5OK(options)) {

      oSound = make();</pre></div></div>
            
        </li>
        
        
        <li id="section-37">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-37">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!sm2.html5Only) {
        sm2._wD(options.id + <span class="string">': Using HTML5'</span>);
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-38">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-38">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      oSound._setup_html5(options);

    } <span class="keyword">else</span> {

      <span class="keyword">if</span> (sm2.html5Only) {
        sm2._wD(options.id + <span class="string">': No HTML5 support for this sound, and no Flash. Exiting.'</span>);
        <span class="keyword">return</span> make();
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-39">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-39">&#182;</a>
              </div>
              <p>TODO: Move HTML5/flash checks into generic URL parsing/handling function.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (sm2.html5.usingFlash &amp;&amp; options.url &amp;&amp; options.url.match(<span class="regexp">/data:/i</span>)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-40">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-40">&#182;</a>
              </div>
              <p>data: URIs not supported by Flash, either.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(options.id + <span class="string">': data: URIs not supported via Flash. Exiting.'</span>);
        <span class="keyword">return</span> make();
      }

      <span class="keyword">if</span> (fV &gt; <span class="number">8</span>) {
        <span class="keyword">if</span> (options.isMovieStar === <span class="literal">null</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-41">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-41">&#182;</a>
              </div>
              <p>attempt to detect MPEG-4 formats</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          options.isMovieStar = !!(options.serverURL || (options.type ? options.type.match(netStreamMimeTypes) : <span class="literal">false</span>) || (options.url &amp;&amp; options.url.match(netStreamPattern)));
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-42">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-42">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (options.isMovieStar) {
          sm2._wD(cs + <span class="string">'using MovieStar handling'</span>);
          <span class="keyword">if</span> (options.loops &gt; <span class="number">1</span>) {
            _wDS(<span class="string">'noNSLoop'</span>);
          }
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-43">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-43">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      }

      options = policyFix(options, cs);
      oSound = make();

      <span class="keyword">if</span> (fV === <span class="number">8</span>) {
        flash._createSound(options.id, options.loops || <span class="number">1</span>, options.usePolicyFile);
      } <span class="keyword">else</span> {
        flash._createSound(options.id, options.url, options.usePeakData, options.useWaveformData, options.useEQData, options.isMovieStar, (options.isMovieStar ? options.bufferTime : <span class="literal">false</span>), options.loops || <span class="number">1</span>, options.serverURL, options.duration || <span class="literal">null</span>, options.autoPlay, <span class="literal">true</span>, options.autoLoad, options.usePolicyFile);
        <span class="keyword">if</span> (!options.serverURL) {</pre></div></div>
            
        </li>
        
        
        <li id="section-44">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-44">&#182;</a>
              </div>
              <p>We are connected immediately</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          oSound.connected = <span class="literal">true</span>;
          <span class="keyword">if</span> (options.onconnect) {
            options.onconnect.apply(oSound);
          }
        }
      }

      <span class="keyword">if</span> (!options.serverURL &amp;&amp; (options.autoLoad || options.autoPlay)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-45">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-45">&#182;</a>
              </div>
              <p>call load for non-rtmp streams</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        oSound.load(options);
      }

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-46">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-46">&#182;</a>
              </div>
              <p>rtmp will play in onconnect</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (!options.serverURL &amp;&amp; options.autoPlay) {
      oSound.play();
    }

    <span class="keyword">return</span> oSound;

  };

  <span class="comment">/**
   * Destroys a SMSound sound object instance.
   *
   * @param {string} sID The ID of the sound to destroy
   */</span>

  <span class="keyword">this</span>.destroySound = <span class="keyword">function</span>(sID, _bFromSound) {</pre></div></div>
            
        </li>
        
        
        <li id="section-47">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-47">&#182;</a>
              </div>
              <p>explicitly destroy a sound before normal page unload, etc.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">var</span> oS = sm2.sounds[sID], i;

    oS.stop();</pre></div></div>
            
        </li>
        
        
        <li id="section-48">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-48">&#182;</a>
              </div>
              <p>Disable all callbacks after stop(), when the sound is being destroyed</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    oS._iO = {};

    oS.unload();

    <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; sm2.soundIDs.length; i++) {
      <span class="keyword">if</span> (sm2.soundIDs[i] === sID) {
        sm2.soundIDs.splice(i, <span class="number">1</span>);
        <span class="keyword">break</span>;
      }
    }

    <span class="keyword">if</span> (!_bFromSound) {</pre></div></div>
            
        </li>
        
        
        <li id="section-49">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-49">&#182;</a>
              </div>
              <p>ignore if being called from SMSound instance</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      oS.destruct(<span class="literal">true</span>);
    }

    oS = <span class="literal">null</span>;
    <span class="keyword">delete</span> sm2.sounds[sID];

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  <span class="comment">/**
   * Calls the load() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @param {object} oOptions Optional: Sound options
   */</span>

  <span class="keyword">this</span>.load = <span class="keyword">function</span>(sID, oOptions) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].load(oOptions);

  };

  <span class="comment">/**
   * Calls the unload() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   */</span>

  <span class="keyword">this</span>.unload = <span class="keyword">function</span>(sID) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].unload();

  };

  <span class="comment">/**
   * Calls the onPosition() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @param {number} nPosition The position to watch for
   * @param {function} oMethod The relevant callback to fire
   * @param {object} oScope Optional: The scope to apply the callback to
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.onPosition = <span class="keyword">function</span>(sID, nPosition, oMethod, oScope) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].onposition(nPosition, oMethod, oScope);

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-50">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-50">&#182;</a>
              </div>
              <p>legacy/backwards-compability: lower-case method name</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>.onposition = <span class="keyword">this</span>.onPosition;

  <span class="comment">/**
   * Calls the clearOnPosition() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @param {number} nPosition The position to watch for
   * @param {function} oMethod Optional: The relevant callback to fire
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.clearOnPosition = <span class="keyword">function</span>(sID, nPosition, oMethod) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].clearOnPosition(nPosition, oMethod);

  };

  <span class="comment">/**
   * Calls the play() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @param {object} oOptions Optional: Sound options
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.play = <span class="keyword">function</span>(sID, oOptions) {

    <span class="keyword">var</span> result = <span class="literal">null</span>,</pre></div></div>
            
        </li>
        
        
        <li id="section-51">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-51">&#182;</a>
              </div>
              <p>legacy function-overloading use case: play(&#39;mySound&#39;, &#39;/path/to/some.mp3&#39;);</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        overloaded = (oOptions &amp;&amp; !(oOptions <span class="keyword">instanceof</span> Object));

    <span class="keyword">if</span> (!didInit || !sm2.ok()) {
      complain(sm + <span class="string">'.play(): '</span> + str(!didInit ? <span class="string">'notReady'</span> : <span class="string">'notOK'</span>));
      <span class="keyword">return</span> <span class="literal">false</span>;
    }

    <span class="keyword">if</span> (!idCheck(sID, overloaded)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-52">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-52">&#182;</a>
              </div>
              <p>no sound found for the given ID. Bail.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!overloaded) <span class="keyword">return</span> <span class="literal">false</span>;

      <span class="keyword">if</span> (overloaded) {
        oOptions = {
          url: oOptions
        };
      }

      <span class="keyword">if</span> (oOptions &amp;&amp; oOptions.url) {</pre></div></div>
            
        </li>
        
        
        <li id="section-53">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-53">&#182;</a>
              </div>
              <p>overloading use case, create+play: .play(&#39;someID&#39;, {url:&#39;/path/to.mp3&#39;});</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(sm + <span class="string">'.play(): Attempting to create "'</span> + sID + <span class="string">'"'</span>, <span class="number">1</span>);
        oOptions.id = sID;
        result = sm2.createSound(oOptions).play();
      }

    } <span class="keyword">else</span> <span class="keyword">if</span> (overloaded) {</pre></div></div>
            
        </li>
        
        
        <li id="section-54">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-54">&#182;</a>
              </div>
              <p>existing sound object case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      oOptions = {
        url: oOptions
      };

    }

    <span class="keyword">if</span> (result === <span class="literal">null</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-55">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-55">&#182;</a>
              </div>
              <p>default case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = sm2.sounds[sID].play(oOptions);
    }

    <span class="keyword">return</span> result;

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-56">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-56">&#182;</a>
              </div>
              <p>just for convenience</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>.start = <span class="keyword">this</span>.play;

  <span class="comment">/**
   * Calls the setPlaybackRate() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.setPlaybackRate = <span class="keyword">function</span>(sID, rate, allowOverride) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].setPlaybackRate(rate, allowOverride);

  };

  <span class="comment">/**
   * Calls the setPosition() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @param {number} nMsecOffset Position (milliseconds)
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.setPosition = <span class="keyword">function</span>(sID, nMsecOffset) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].setPosition(nMsecOffset);

  };

  <span class="comment">/**
   * Calls the stop() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.stop = <span class="keyword">function</span>(sID) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    sm2._wD(sm + <span class="string">'.stop('</span> + sID + <span class="string">')'</span>, <span class="number">1</span>);

    <span class="keyword">return</span> sm2.sounds[sID].stop();

  };

  <span class="comment">/**
   * Stops all currently-playing sounds.
   */</span>

  <span class="keyword">this</span>.stopAll = <span class="keyword">function</span>() {

    <span class="keyword">var</span> oSound;
    sm2._wD(sm + <span class="string">'.stopAll()'</span>, <span class="number">1</span>);

    <span class="keyword">for</span> (oSound <span class="keyword">in</span> sm2.sounds) {
      <span class="keyword">if</span> (sm2.sounds.hasOwnProperty(oSound)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-57">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-57">&#182;</a>
              </div>
              <p>apply only to sound objects</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2.sounds[oSound].stop();
      }
    }

  };

  <span class="comment">/**
   * Calls the pause() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.pause = <span class="keyword">function</span>(sID) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].pause();

  };

  <span class="comment">/**
   * Pauses all currently-playing sounds.
   */</span>

  <span class="keyword">this</span>.pauseAll = <span class="keyword">function</span>() {

    <span class="keyword">var</span> i;
    <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
      sm2.sounds[sm2.soundIDs[i]].pause();
    }

  };

  <span class="comment">/**
   * Calls the resume() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.resume = <span class="keyword">function</span>(sID) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].resume();

  };

  <span class="comment">/**
   * Resumes all currently-paused sounds.
   */</span>

  <span class="keyword">this</span>.resumeAll = <span class="keyword">function</span>() {

    <span class="keyword">var</span> i;
    <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
      sm2.sounds[sm2.soundIDs[i]].resume();
    }

  };

  <span class="comment">/**
   * Calls the togglePause() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.togglePause = <span class="keyword">function</span>(sID) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].togglePause();

  };

  <span class="comment">/**
   * Calls the setPan() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @param {number} nPan The pan value (-100 to 100)
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.setPan = <span class="keyword">function</span>(sID, nPan) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].setPan(nPan);

  };

  <span class="comment">/**
   * Calls the setVolume() method of a SMSound object by ID
   * Overloaded case: pass only volume argument eg., setVolume(50) to apply to all sounds.
   *
   * @param {string} sID The ID of the sound
   * @param {number} nVol The volume value (0 to 100)
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.setVolume = <span class="keyword">function</span>(sID, nVol) {</pre></div></div>
            
        </li>
        
        
        <li id="section-58">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-58">&#182;</a>
              </div>
              <p>setVolume(50) function overloading case - apply to all sounds</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> i, j;

    <span class="keyword">if</span> (sID !== _<span class="literal">undefined</span> &amp;&amp; !isNaN(sID) &amp;&amp; nVol === _<span class="literal">undefined</span>) {
      <span class="keyword">for</span> (i = <span class="number">0</span>, j = sm2.soundIDs.length; i &lt; j; i++) {
        sm2.sounds[sm2.soundIDs[i]].setVolume(sID);
      }
      <span class="keyword">return</span> <span class="literal">false</span>;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-59">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-59">&#182;</a>
              </div>
              <p>setVolume(&#39;mySound&#39;, 50) case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].setVolume(nVol);

  };

  <span class="comment">/**
   * Calls the mute() method of either a single SMSound object by ID, or all sound objects.
   *
   * @param {string} sID Optional: The ID of the sound (if omitted, all sounds will be used.)
   */</span>

  <span class="keyword">this</span>.mute = <span class="keyword">function</span>(sID) {

    <span class="keyword">var</span> i = <span class="number">0</span>;

    <span class="keyword">if</span> (sID <span class="keyword">instanceof</span> String) {
      sID = <span class="literal">null</span>;
    }

    <span class="keyword">if</span> (!sID) {

      sm2._wD(sm + <span class="string">'.mute(): Muting all sounds'</span>);
      <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
        sm2.sounds[sm2.soundIDs[i]].mute();
      }
      sm2.muted = <span class="literal">true</span>;

    } <span class="keyword">else</span> {

      <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

      sm2._wD(sm + <span class="string">'.mute(): Muting "'</span> + sID + <span class="string">'"'</span>);
      <span class="keyword">return</span> sm2.sounds[sID].mute();

    }

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  <span class="comment">/**
   * Mutes all sounds.
   */</span>

  <span class="keyword">this</span>.muteAll = <span class="keyword">function</span>() {

    sm2.mute();

  };

  <span class="comment">/**
   * Calls the unmute() method of either a single SMSound object by ID, or all sound objects.
   *
   * @param {string} sID Optional: The ID of the sound (if omitted, all sounds will be used.)
   */</span>

  <span class="keyword">this</span>.unmute = <span class="keyword">function</span>(sID) {

    <span class="keyword">var</span> i;

    <span class="keyword">if</span> (sID <span class="keyword">instanceof</span> String) {
      sID = <span class="literal">null</span>;
    }

    <span class="keyword">if</span> (!sID) {

      sm2._wD(sm + <span class="string">'.unmute(): Unmuting all sounds'</span>);
      <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
        sm2.sounds[sm2.soundIDs[i]].unmute();
      }
      sm2.muted = <span class="literal">false</span>;

    } <span class="keyword">else</span> {

      <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

      sm2._wD(sm + <span class="string">'.unmute(): Unmuting "'</span> + sID + <span class="string">'"'</span>);

      <span class="keyword">return</span> sm2.sounds[sID].unmute();

    }

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  <span class="comment">/**
   * Unmutes all sounds.
   */</span>

  <span class="keyword">this</span>.unmuteAll = <span class="keyword">function</span>() {

    sm2.unmute();

  };

  <span class="comment">/**
   * Calls the toggleMute() method of a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.toggleMute = <span class="keyword">function</span>(sID) {

    <span class="keyword">if</span> (!idCheck(sID)) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">return</span> sm2.sounds[sID].toggleMute();

  };

  <span class="comment">/**
   * Retrieves the memory used by the flash plugin.
   *
   * @return {number} The amount of memory in use
   */</span>

  <span class="keyword">this</span>.getMemoryUse = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-60">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-60">&#182;</a>
              </div>
              <p>flash-only</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> ram = <span class="number">0</span>;

    <span class="keyword">if</span> (flash &amp;&amp; fV !== <span class="number">8</span>) {
      ram = parseInt(flash._getMemoryUse(), <span class="number">10</span>);
    }

    <span class="keyword">return</span> ram;

  };

  <span class="comment">/**
   * Undocumented: NOPs soundManager and all SMSound objects.
   */</span>

  <span class="keyword">this</span>.disable = <span class="keyword">function</span>(bNoDisable) {</pre></div></div>
            
        </li>
        
        
        <li id="section-61">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-61">&#182;</a>
              </div>
              <p>destroy all functions</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> i;

    <span class="keyword">if</span> (bNoDisable === _<span class="literal">undefined</span>) {
      bNoDisable = <span class="literal">false</span>;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-62">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-62">&#182;</a>
              </div>
              <p>already disabled?</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (disabled) <span class="keyword">return</span> <span class="literal">false</span>;

    disabled = <span class="literal">true</span>;

    _wDS(<span class="string">'shutdown'</span>, <span class="number">1</span>);

    <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
      disableObject(sm2.sounds[sm2.soundIDs[i]]);
    }

    disableObject(sm2);</pre></div></div>
            
        </li>
        
        
        <li id="section-63">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-63">&#182;</a>
              </div>
              <p>fire &quot;complete&quot;, despite fail</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    initComplete(bNoDisable);

    event.remove(window, <span class="string">'load'</span>, initUserOnload);

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  <span class="comment">/**
   * Determines playability of a MIME type, eg. 'audio/mp3'.
   */</span>

  <span class="keyword">this</span>.canPlayMIME = <span class="keyword">function</span>(sMIME) {

    <span class="keyword">var</span> result;

    <span class="keyword">if</span> (sm2.hasHTML5) {
      result = html5CanPlay({
        type: sMIME
      });
    }

    <span class="keyword">if</span> (!result &amp;&amp; needsFlash) {</pre></div></div>
            
        </li>
        
        
        <li id="section-64">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-64">&#182;</a>
              </div>
              <p>if flash 9, test netStream (movieStar) types as well.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = (sMIME &amp;&amp; sm2.ok() ? !!((fV &gt; <span class="number">8</span> ? sMIME.match(netStreamMimeTypes) : <span class="literal">null</span>) || sMIME.match(sm2.mimePattern)) : <span class="literal">null</span>); <span class="comment">// TODO: make less "weird" (per JSLint)</span>
    }

    <span class="keyword">return</span> result;

  };

  <span class="comment">/**
   * Determines playability of a URL based on audio support.
   *
   * @param {string} sURL The URL to test
   * @return {boolean} URL playability
   */</span>

  <span class="keyword">this</span>.canPlayURL = <span class="keyword">function</span>(sURL) {

    <span class="keyword">var</span> result;

    <span class="keyword">if</span> (sm2.hasHTML5) {
      result = html5CanPlay({
        url: sURL
      });
    }

    <span class="keyword">if</span> (!result &amp;&amp; needsFlash) {
      result = (sURL &amp;&amp; sm2.ok() ? !!(sURL.match(sm2.filePattern)) : <span class="literal">null</span>);
    }

    <span class="keyword">return</span> result;

  };

  <span class="comment">/**
   * Determines playability of an HTML DOM &amp;lt;a&amp;gt; object (or similar object literal) based on audio support.
   *
   * @param {object} oLink an HTML DOM &amp;lt;a&amp;gt; object or object literal including href and/or type attributes
   * @return {boolean} URL playability
   */</span>

  <span class="keyword">this</span>.canPlayLink = <span class="keyword">function</span>(oLink) {

    <span class="keyword">if</span> (oLink.type !== _<span class="literal">undefined</span> &amp;&amp; oLink.type &amp;&amp; sm2.canPlayMIME(oLink.type)) <span class="keyword">return</span> <span class="literal">true</span>;

    <span class="keyword">return</span> sm2.canPlayURL(oLink.href);

  };

  <span class="comment">/**
   * Retrieves a SMSound object by ID.
   *
   * @param {string} sID The ID of the sound
   * @return {SMSound} The SMSound object
   */</span>

  <span class="keyword">this</span>.getSoundById = <span class="keyword">function</span>(sID, _suppressDebug) {

    <span class="keyword">if</span> (!sID) <span class="keyword">return</span> <span class="literal">null</span>;

    <span class="keyword">var</span> result = sm2.sounds[sID];</pre></div></div>
            
        </li>
        
        
        <li id="section-65">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-65">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (!result &amp;&amp; !_suppressDebug) {
      sm2._wD(sm + <span class="string">'.getSoundById(): Sound "'</span> + sID + <span class="string">'" not found.'</span>, <span class="number">2</span>);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-66">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-66">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">return</span> result;

  };

  <span class="comment">/**
   * Queues a callback for execution when SoundManager has successfully initialized.
   *
   * @param {function} oMethod The callback method to fire
   * @param {object} oScope Optional: The scope to apply to the callback
   */</span>

  <span class="keyword">this</span>.onready = <span class="keyword">function</span>(oMethod, oScope) {

    <span class="keyword">var</span> sType = <span class="string">'onready'</span>,
        result = <span class="literal">false</span>;

    <span class="keyword">if</span> (<span class="keyword">typeof</span> oMethod === <span class="string">'function'</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-67">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-67">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (didInit) {
        sm2._wD(str(<span class="string">'queue'</span>, sType));
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-68">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-68">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (!oScope) {
        oScope = window;
      }

      addOnEvent(sType, oMethod, oScope);
      processOnEvents();

      result = <span class="literal">true</span>;

    } <span class="keyword">else</span> {

      <span class="keyword">throw</span> str(<span class="string">'needFunction'</span>, sType);

    }

    <span class="keyword">return</span> result;

  };

  <span class="comment">/**
   * Queues a callback for execution when SoundManager has failed to initialize.
   *
   * @param {function} oMethod The callback method to fire
   * @param {object} oScope Optional: The scope to apply to the callback
   */</span>

  <span class="keyword">this</span>.ontimeout = <span class="keyword">function</span>(oMethod, oScope) {

    <span class="keyword">var</span> sType = <span class="string">'ontimeout'</span>,
        result = <span class="literal">false</span>;

    <span class="keyword">if</span> (<span class="keyword">typeof</span> oMethod === <span class="string">'function'</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-69">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-69">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (didInit) {
        sm2._wD(str(<span class="string">'queue'</span>, sType));
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-70">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-70">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (!oScope) {
        oScope = window;
      }

      addOnEvent(sType, oMethod, oScope);
      processOnEvents({ type: sType });

      result = <span class="literal">true</span>;

    } <span class="keyword">else</span> {

      <span class="keyword">throw</span> str(<span class="string">'needFunction'</span>, sType);

    }

    <span class="keyword">return</span> result;

  };

  <span class="comment">/**
   * Writes console.log()-style debug output to a console or in-browser element.
   * Applies when debugMode = true
   *
   * @param {string} sText The console message
   * @param {object} nType Optional log level (number), or object. Number case: Log type/style where 0 = 'info', 1 = 'warn', 2 = 'error'. Object case: Object to be dumped.
   */</span>

  <span class="keyword">this</span>._writeDebug = <span class="keyword">function</span>(sText, sTypeOrObject) {</pre></div></div>
            
        </li>
        
        
        <li id="section-71">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-71">&#182;</a>
              </div>
              <p>pseudo-private console.log()-style output</p>
<d>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> sDID = <span class="string">'soundmanager-debug'</span>, o, oItem;

    <span class="keyword">if</span> (!sm2.setupOptions.debugMode) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">if</span> (hasConsole &amp;&amp; sm2.useConsole) {
      <span class="keyword">if</span> (sTypeOrObject &amp;&amp; <span class="keyword">typeof</span> sTypeOrObject === <span class="string">'object'</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-72">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-72">&#182;</a>
              </div>
              <p>object passed; dump to console.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        console.log(sText, sTypeOrObject);
      } <span class="keyword">else</span> <span class="keyword">if</span> (debugLevels[sTypeOrObject] !== _<span class="literal">undefined</span>) {
        console[debugLevels[sTypeOrObject]](sText);
      } <span class="keyword">else</span> {
        console.log(sText);
      }
      <span class="keyword">if</span> (sm2.consoleOnly) <span class="keyword">return</span> <span class="literal">true</span>;
    }

    o = id(sDID);

    <span class="keyword">if</span> (!o) <span class="keyword">return</span> <span class="literal">false</span>;

    oItem = doc.createElement(<span class="string">'div'</span>);

    <span class="keyword">if</span> (++wdCount % <span class="number">2</span> === <span class="number">0</span>) {
      oItem.className = <span class="string">'sm2-alt'</span>;
    }

    <span class="keyword">if</span> (sTypeOrObject === _<span class="literal">undefined</span>) {
      sTypeOrObject = <span class="number">0</span>;
    } <span class="keyword">else</span> {
      sTypeOrObject = parseInt(sTypeOrObject, <span class="number">10</span>);
    }

    oItem.appendChild(doc.createTextNode(sText));

    <span class="keyword">if</span> (sTypeOrObject) {
      <span class="keyword">if</span> (sTypeOrObject &gt;= <span class="number">2</span>) {
        oItem.style.fontWeight = <span class="string">'bold'</span>;
      }
      <span class="keyword">if</span> (sTypeOrObject === <span class="number">3</span>) {
        oItem.style.color = <span class="string">'#ff3333'</span>;
      }
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-73">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-73">&#182;</a>
              </div>
              <p>top-to-bottom
o.appendChild(oItem);</p>

            </div>
            
        </li>
        
        
        <li id="section-74">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-74">&#182;</a>
              </div>
              <p>bottom-to-top</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    o.insertBefore(oItem, o.firstChild);

    o = <span class="literal">null</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-75">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-75">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">return</span> <span class="literal">true</span>;

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-76">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-76">&#182;</a>
              </div>
              <p><d>
last-resort debugging option</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">if</span> (wl.indexOf(<span class="string">'sm2-debug=alert'</span>) !== -<span class="number">1</span>) {
    <span class="keyword">this</span>._writeDebug = <span class="keyword">function</span>(sText) {
      window.alert(sText);
    };
  }</pre></div></div>
            
        </li>
        
        
        <li id="section-77">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-77">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
        </li>
        
        
        <li id="section-78">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-78">&#182;</a>
              </div>
              <p>alias</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">this</span>._wD = <span class="keyword">this</span>._writeDebug;

  <span class="comment">/**
   * Provides debug / state information on all SMSound objects.
   */</span>

  <span class="keyword">this</span>._debug = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-79">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-79">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> i, j;
    _wDS(<span class="string">'currentObj'</span>, <span class="number">1</span>);

    <span class="keyword">for</span> (i = <span class="number">0</span>, j = sm2.soundIDs.length; i &lt; j; i++) {
      sm2.sounds[sm2.soundIDs[i]]._debug();
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-80">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-80">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  <span class="comment">/**
   * Restarts and re-initializes the SoundManager instance.
   *
   * @param {boolean} resetEvents Optional: When true, removes all registered onready and ontimeout event callbacks.
   * @param {boolean} excludeInit Options: When true, does not call beginDelayedInit() (which would restart SM2).
   * @return {object} soundManager The soundManager instance.
   */</span>

  <span class="keyword">this</span>.reboot = <span class="keyword">function</span>(resetEvents, excludeInit) {</pre></div></div>
            
        </li>
        
        
        <li id="section-81">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-81">&#182;</a>
              </div>
              <p>reset some (or all) state, and re-init unless otherwise specified.</p>

            </div>
            
        </li>
        
        
        <li id="section-82">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-82">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (sm2.soundIDs.length) {
      sm2._wD(<span class="string">'Destroying '</span> + sm2.soundIDs.length + <span class="string">' SMSound object'</span> + (sm2.soundIDs.length !== <span class="number">1</span> ? <span class="string">'s'</span> : <span class="string">''</span>) + <span class="string">'...'</span>);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-83">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-83">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> i, j, k;

    <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
      sm2.sounds[sm2.soundIDs[i]].destruct();
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-84">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-84">&#182;</a>
              </div>
              <p>trash ze flash (remove from the DOM)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (flash) {

      <span class="keyword">try</span> {

        <span class="keyword">if</span> (isIE) {
          oRemovedHTML = flash.innerHTML;
        }

        oRemoved = flash.parentNode.removeChild(flash);

      } <span class="keyword">catch</span>(e) {</pre></div></div>
            
        </li>
        
        
        <li id="section-85">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-85">&#182;</a>
              </div>
              <p>Remove failed? May be due to flash blockers silently removing the SWF object/embed node from the DOM. Warn and continue.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        _wDS(<span class="string">'badRemove'</span>, <span class="number">2</span>);

      }

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-86">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-86">&#182;</a>
              </div>
              <p>actually, force recreate of movie.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    oRemovedHTML = oRemoved = needsFlash = flash = <span class="literal">null</span>;

    sm2.enabled = didDCLoaded = didInit = waitingForEI = initPending = didAppend = appendSuccess = disabled = useGlobalHTML5Audio = sm2.swfLoaded = <span class="literal">false</span>;

    sm2.soundIDs = [];
    sm2.sounds = {};

    idCounter = <span class="number">0</span>;
    didSetup = <span class="literal">false</span>;

    <span class="keyword">if</span> (!resetEvents) {</pre></div></div>
            
        </li>
        
        
        <li id="section-87">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-87">&#182;</a>
              </div>
              <p>reset callbacks for onready, ontimeout etc. so that they will fire again on re-init</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">for</span> (i <span class="keyword">in</span> on_queue) {
        <span class="keyword">if</span> (on_queue.hasOwnProperty(i)) {
          <span class="keyword">for</span> (j = <span class="number">0</span>, k = on_queue[i].length; j &lt; k; j++) {
            on_queue[i][j].fired = <span class="literal">false</span>;
          }
        }
      }
    } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-88">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-88">&#182;</a>
              </div>
              <p>remove all callbacks entirely</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      on_queue = [];
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-89">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-89">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (!excludeInit) {
      sm2._wD(sm + <span class="string">': Rebooting...'</span>);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-90">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-90">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
        </li>
        
        
        <li id="section-91">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-91">&#182;</a>
              </div>
              <p>reset HTML5 and flash canPlay test results</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    sm2.html5 = {
      usingFlash: <span class="literal">null</span>
    };

    sm2.flash = {};</pre></div></div>
            
        </li>
        
        
        <li id="section-92">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-92">&#182;</a>
              </div>
              <p>reset device-specific HTML/flash mode switches</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    sm2.html5Only = <span class="literal">false</span>;
    sm2.ignoreFlash = <span class="literal">false</span>;

    window.setTimeout(<span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-93">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-93">&#182;</a>
              </div>
              <p>by default, re-init</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (!excludeInit) {
        sm2.beginDelayedInit();
      }

    }, <span class="number">20</span>);

    <span class="keyword">return</span> sm2;

  };

  <span class="keyword">this</span>.reset = <span class="keyword">function</span>() {

    <span class="comment">/**
     * Shuts down and restores the SoundManager instance to its original loaded state, without an explicit reboot. All onready/ontimeout handlers are removed.
     * After this call, SM2 may be re-initialized via soundManager.beginDelayedInit().
     * @return {object} soundManager The soundManager instance.
     */</span>

    _wDS(<span class="string">'reset'</span>);

    <span class="keyword">return</span> sm2.reboot(<span class="literal">true</span>, <span class="literal">true</span>);

  };

  <span class="comment">/**
   * Undocumented: Determines the SM2 flash movie's load progress.
   *
   * @return {number or null} Percent loaded, or if invalid/unsupported, null.
   */</span>

  <span class="keyword">this</span>.getMoviePercent = <span class="keyword">function</span>() {

    <span class="comment">/**
     * Interesting syntax notes...
     * Flash/ExternalInterface (ActiveX/NPAPI) bridge methods are not typeof "function" nor instanceof Function, but are still valid.
     * Furthermore, using (flash &amp;&amp; flash.PercentLoaded) causes IE to throw "object doesn't support this property or method".
     * Thus, 'in' syntax must be used.
     */</span>

    <span class="keyword">return</span> (flash &amp;&amp; <span class="string">'PercentLoaded'</span> <span class="keyword">in</span> flash ? flash.PercentLoaded() : <span class="literal">null</span>);

  };

  <span class="comment">/**
   * Additional helper for manually invoking SM2's init process after DOM Ready / window.onload().
   */</span>

  <span class="keyword">this</span>.beginDelayedInit = <span class="keyword">function</span>() {

    windowLoaded = <span class="literal">true</span>;
    domContentLoaded();

    setTimeout(<span class="keyword">function</span>() {

      <span class="keyword">if</span> (initPending) <span class="keyword">return</span> <span class="literal">false</span>;

      createMovie();
      initMovie();
      initPending = <span class="literal">true</span>;

      <span class="keyword">return</span> <span class="literal">true</span>;

    }, <span class="number">20</span>);

    delayWaitForEI();

  };

  <span class="comment">/**
   * Destroys the SoundManager instance and all SMSound instances.
   */</span>

  <span class="keyword">this</span>.destruct = <span class="keyword">function</span>() {

    sm2._wD(sm + <span class="string">'.destruct()'</span>);
    sm2.disable(<span class="literal">true</span>);

  };

  <span class="comment">/**
   * SMSound() (sound object) constructor
   * ------------------------------------
   *
   * @param {object} oOptions Sound options (id and url are required attributes)
   * @return {SMSound} The new SMSound object
   */</span>

  SMSound = <span class="keyword">function</span>(oOptions) {

    <span class="keyword">var</span> s = <span class="keyword">this</span>, resetProperties, add_html5_events, remove_html5_events, stop_html5_timer, start_html5_timer, attachOnPosition, onplay_called = <span class="literal">false</span>, onPositionItems = [], onPositionFired = <span class="number">0</span>, detachOnPosition, applyFromTo, lastURL = <span class="literal">null</span>, lastHTML5State, urlOmitted;

    lastHTML5State = {</pre></div></div>
            
        </li>
        
        
        <li id="section-94">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-94">&#182;</a>
              </div>
              <p>tracks duration + position (time)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      duration: <span class="literal">null</span>,
      time: <span class="literal">null</span>
    };

    <span class="keyword">this</span>.id = oOptions.id;</pre></div></div>
            
        </li>
        
        
        <li id="section-95">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-95">&#182;</a>
              </div>
              <p>legacy</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>.sID = <span class="keyword">this</span>.id;

    <span class="keyword">this</span>.url = oOptions.url;
    <span class="keyword">this</span>.options = mixin(oOptions);</pre></div></div>
            
        </li>
        
        
        <li id="section-96">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-96">&#182;</a>
              </div>
              <p>per-play-instance-specific options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>.instanceOptions = <span class="keyword">this</span>.options;</pre></div></div>
            
        </li>
        
        
        <li id="section-97">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-97">&#182;</a>
              </div>
              <p>short alias</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>._iO = <span class="keyword">this</span>.instanceOptions;</pre></div></div>
            
        </li>
        
        
        <li id="section-98">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-98">&#182;</a>
              </div>
              <p>assign property defaults</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>.pan = <span class="keyword">this</span>.options.pan;
    <span class="keyword">this</span>.volume = <span class="keyword">this</span>.options.volume;</pre></div></div>
            
        </li>
        
        
        <li id="section-99">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-99">&#182;</a>
              </div>
              <p>whether or not this object is using HTML5</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>.isHTML5 = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-100">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-100">&#182;</a>
              </div>
              <p>internal HTML5 Audio() object reference</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>._a = <span class="literal">null</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-101">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-101">&#182;</a>
              </div>
              <p>for flash 8 special-case createSound() without url, followed by load/play with url case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    urlOmitted = (!<span class="keyword">this</span>.url);

    <span class="comment">/**
     * SMSound() public methods
     * ------------------------
     */</span>

    <span class="keyword">this</span>.id3 = {};

    <span class="comment">/**
     * Writes SMSound object parameters to debug console
     */</span>

    <span class="keyword">this</span>._debug = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-102">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-102">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2._wD(s.id + <span class="string">': Merged options:'</span>, s.options);</pre></div></div>
            
        </li>
        
        
        <li id="section-103">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-103">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    };

    <span class="comment">/**
     * Begins loading a sound per its *url*.
     *
     * @param {object} options Optional: Sound options
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.load = <span class="keyword">function</span>(options) {

      <span class="keyword">var</span> oSound = <span class="literal">null</span>, instanceOptions;

      <span class="keyword">if</span> (options !== _<span class="literal">undefined</span>) {
        s._iO = mixin(options, s.options);
      } <span class="keyword">else</span> {
        options = s.options;
        s._iO = options;
        <span class="keyword">if</span> (lastURL &amp;&amp; lastURL !== s.url) {
          _wDS(<span class="string">'manURL'</span>);
          s._iO.url = s.url;
          s.url = <span class="literal">null</span>;
        }
      }

      <span class="keyword">if</span> (!s._iO.url) {
        s._iO.url = s.url;
      }

      s._iO.url = parseURL(s._iO.url);</pre></div></div>
            
        </li>
        
        
        <li id="section-104">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-104">&#182;</a>
              </div>
              <p>ensure we&#39;re in sync</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s.instanceOptions = s._iO;</pre></div></div>
            
        </li>
        
        
        <li id="section-105">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-105">&#182;</a>
              </div>
              <p>local shortcut</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      instanceOptions = s._iO;

      sm2._wD(s.id + <span class="string">': load ('</span> + instanceOptions.url + <span class="string">')'</span>);

      <span class="keyword">if</span> (!instanceOptions.url &amp;&amp; !s.url) {
        sm2._wD(s.id + <span class="string">': load(): url is unassigned. Exiting.'</span>, <span class="number">2</span>);
        <span class="keyword">return</span> s;
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-106">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-106">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; fV === <span class="number">8</span> &amp;&amp; !s.url &amp;&amp; !instanceOptions.autoPlay) {</pre></div></div>
            
        </li>
        
        
        <li id="section-107">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-107">&#182;</a>
              </div>
              <p>flash 8 load() -&gt; play() won&#39;t work before onload has fired.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(s.id + <span class="string">': Flash 8 load() limitation: Wait for onload() before calling play().'</span>, <span class="number">1</span>);
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-108">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-108">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (instanceOptions.url === s.url &amp;&amp; s.readyState !== <span class="number">0</span> &amp;&amp; s.readyState !== <span class="number">2</span>) {
        _wDS(<span class="string">'onURL'</span>, <span class="number">1</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-109">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-109">&#182;</a>
              </div>
              <p>if loaded and an onload() exists, fire immediately.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (s.readyState === <span class="number">3</span> &amp;&amp; instanceOptions.onload) {</pre></div></div>
            
        </li>
        
        
        <li id="section-110">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-110">&#182;</a>
              </div>
              <p>assume success based on truthy duration.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          wrapCallback(s, <span class="keyword">function</span>() {
            instanceOptions.onload.apply(s, [(!!s.duration)]);
          });
        }
        <span class="keyword">return</span> s;
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-111">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-111">&#182;</a>
              </div>
              <p>reset a few state properties</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      s.loaded = <span class="literal">false</span>;
      s.readyState = <span class="number">1</span>;
      s.playState = <span class="number">0</span>;
      s.id3 = {};</pre></div></div>
            
        </li>
        
        
        <li id="section-112">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-112">&#182;</a>
              </div>
              <p>TODO: If switching from HTML5 -&gt; flash (or vice versa), stop currently-playing audio.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (html5OK(instanceOptions)) {

        oSound = s._setup_html5(instanceOptions);

        <span class="keyword">if</span> (!oSound._called_load) {

          s._html5_canplay = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-113">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-113">&#182;</a>
              </div>
              <p>TODO: review called_load / html5_canplay logic</p>

            </div>
            
        </li>
        
        
        <li id="section-114">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-114">&#182;</a>
              </div>
              <p>if url provided directly to load(), assign it here.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          <span class="keyword">if</span> (s.url !== instanceOptions.url) {

            sm2._wD(_wDS(<span class="string">'manURL'</span>) + <span class="string">': '</span> + instanceOptions.url);

            s._a.src = instanceOptions.url;</pre></div></div>
            
        </li>
        
        
        <li id="section-115">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-115">&#182;</a>
              </div>
              <p>TODO: review / re-apply all relevant options (volume, loop, onposition etc.)</p>

            </div>
            
        </li>
        
        
        <li id="section-116">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-116">&#182;</a>
              </div>
              <p>reset position for new URL</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s.setPosition(<span class="number">0</span>);

          }</pre></div></div>
            
        </li>
        
        
        <li id="section-117">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-117">&#182;</a>
              </div>
              <p>given explicit load call, try to preload.</p>

            </div>
            
        </li>
        
        
        <li id="section-118">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-118">&#182;</a>
              </div>
              <p>early HTML5 implementation (non-standard)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s._a.autobuffer = <span class="string">'auto'</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-119">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-119">&#182;</a>
              </div>
              <p>standard property, values: none / metadata / auto
reference: <a href="http://msdn.microsoft.com/en-us/library/ie/ff974759%28v=vs.85%29.aspx">http://msdn.microsoft.com/en-us/library/ie/ff974759%28v=vs.85%29.aspx</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s._a.preload = <span class="string">'auto'</span>;

          s._a._called_load = <span class="literal">true</span>;

        } <span class="keyword">else</span> {

          sm2._wD(s.id + <span class="string">': Ignoring request to load again'</span>);

        }

      } <span class="keyword">else</span> {

        <span class="keyword">if</span> (sm2.html5Only) {
          sm2._wD(s.id + <span class="string">': No flash support. Exiting.'</span>);
          <span class="keyword">return</span> s;
        }

        <span class="keyword">if</span> (s._iO.url &amp;&amp; s._iO.url.match(<span class="regexp">/data:/i</span>)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-120">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-120">&#182;</a>
              </div>
              <p>data: URIs not supported by Flash, either.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2._wD(s.id + <span class="string">': data: URIs not supported via Flash. Exiting.'</span>);
          <span class="keyword">return</span> s;
        }

        <span class="keyword">try</span> {
          s.isHTML5 = <span class="literal">false</span>;
          s._iO = policyFix(loopFix(instanceOptions));</pre></div></div>
            
        </li>
        
        
        <li id="section-121">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-121">&#182;</a>
              </div>
              <p>if we have &quot;position&quot;, disable auto-play as we&#39;ll be seeking to that position at onload().</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (s._iO.autoPlay &amp;&amp; (s._iO.position || s._iO.from)) {
            sm2._wD(s.id + <span class="string">': Disabling autoPlay because of non-zero offset case'</span>);
            s._iO.autoPlay = <span class="literal">false</span>;
          }</pre></div></div>
            
        </li>
        
        
        <li id="section-122">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-122">&#182;</a>
              </div>
              <p>re-assign local shortcut</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          instanceOptions = s._iO;
          <span class="keyword">if</span> (fV === <span class="number">8</span>) {
            flash._load(s.id, instanceOptions.url, instanceOptions.stream, instanceOptions.autoPlay, instanceOptions.usePolicyFile);
          } <span class="keyword">else</span> {
            flash._load(s.id, instanceOptions.url, !!(instanceOptions.stream), !!(instanceOptions.autoPlay), instanceOptions.loops || <span class="number">1</span>, !!(instanceOptions.autoLoad), instanceOptions.usePolicyFile);
          }
        } <span class="keyword">catch</span>(e) {
          _wDS(<span class="string">'smError'</span>, <span class="number">2</span>);
          debugTS(<span class="string">'onload'</span>, <span class="literal">false</span>);
          catchError({
            type: <span class="string">'SMSOUND_LOAD_JS_EXCEPTION'</span>,
            fatal: <span class="literal">true</span>
          });
        }

      }</pre></div></div>
            
        </li>
        
        
        <li id="section-123">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-123">&#182;</a>
              </div>
              <p>after all of this, ensure sound url is up to date.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s.url = instanceOptions.url;

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Unloads a sound, canceling any open HTTP requests.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.unload = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-124">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-124">&#182;</a>
              </div>
              <p>Flash 8/AS2 can&#39;t &quot;close&quot; a stream - fake it by loading an empty URL
Flash 9/AS3: Close stream, preventing further load
HTML5: Most UAs will use empty URL</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (s.readyState !== <span class="number">0</span>) {

        sm2._wD(s.id + <span class="string">': unload()'</span>);

        <span class="keyword">if</span> (!s.isHTML5) {

          <span class="keyword">if</span> (fV === <span class="number">8</span>) {
            flash._unload(s.id, emptyURL);
          } <span class="keyword">else</span> {
            flash._unload(s.id);
          }

        } <span class="keyword">else</span> {

          stop_html5_timer();

          <span class="keyword">if</span> (s._a) {

            s._a.pause();</pre></div></div>
            
        </li>
        
        
        <li id="section-125">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-125">&#182;</a>
              </div>
              <p>update empty URL, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            lastURL = html5Unload(s._a);

          }

        }</pre></div></div>
            
        </li>
        
        
        <li id="section-126">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-126">&#182;</a>
              </div>
              <p>reset load/status flags</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        resetProperties();

      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Unloads and destroys a sound.
     */</span>

    <span class="keyword">this</span>.destruct = <span class="keyword">function</span>(_bFromSM) {

      sm2._wD(s.id + <span class="string">': Destruct'</span>);

      <span class="keyword">if</span> (!s.isHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-127">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-127">&#182;</a>
              </div>
              <p>kill sound within Flash
Disable the onfailure handler</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        s._iO.onfailure = <span class="literal">null</span>;
        flash._destroySound(s.id);

      } <span class="keyword">else</span> {

        stop_html5_timer();

        <span class="keyword">if</span> (s._a) {
          s._a.pause();
          html5Unload(s._a);
          <span class="keyword">if</span> (!useGlobalHTML5Audio) {
            remove_html5_events();
          }</pre></div></div>
            
        </li>
        
        
        <li id="section-128">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-128">&#182;</a>
              </div>
              <p>break obvious circular reference</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s._a._s = <span class="literal">null</span>;
          s._a = <span class="literal">null</span>;
        }

      }

      <span class="keyword">if</span> (!_bFromSM) {</pre></div></div>
            
        </li>
        
        
        <li id="section-129">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-129">&#182;</a>
              </div>
              <p>ensure deletion from controller</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2.destroySound(s.id, <span class="literal">true</span>);
      }

    };

    <span class="comment">/**
     * Begins playing a sound.
     *
     * @param {object} options Optional: Sound options
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.play = <span class="keyword">function</span>(options, _updatePlayState) {

      <span class="keyword">var</span> fN, allowMulti, a, onready,
          audioClone, onended, oncanplay,
          startOK = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-130">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-130">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      fN = s.id + <span class="string">': play(): '</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-131">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-131">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
        </li>
        
        
        <li id="section-132">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-132">&#182;</a>
              </div>
              <p>default to true</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      _updatePlayState = (_updatePlayState === _<span class="literal">undefined</span> ? <span class="literal">true</span> : _updatePlayState);

      <span class="keyword">if</span> (!options) {
        options = {};
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-133">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-133">&#182;</a>
              </div>
              <p>first, use local URL (if specified)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (s.url) {
        s._iO.url = s.url;
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-134">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-134">&#182;</a>
              </div>
              <p>mix in any options defined at createSound()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s._iO = mixin(s._iO, s.options);</pre></div></div>
            
        </li>
        
        
        <li id="section-135">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-135">&#182;</a>
              </div>
              <p>mix in any options specific to this method</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s._iO = mixin(options, s._iO);

      s._iO.url = parseURL(s._iO.url);

      s.instanceOptions = s._iO;</pre></div></div>
            
        </li>
        
        
        <li id="section-136">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-136">&#182;</a>
              </div>
              <p>RTMP-only</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; s._iO.serverURL &amp;&amp; !s.connected) {
        <span class="keyword">if</span> (!s.getAutoPlay()) {
          sm2._wD(fN + <span class="string">' Netstream not connected yet - setting autoPlay'</span>);
          s.setAutoPlay(<span class="literal">true</span>);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-137">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-137">&#182;</a>
              </div>
              <p>play will be called in onconnect()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">return</span> s;
      }

      <span class="keyword">if</span> (html5OK(s._iO)) {
        s._setup_html5(s._iO);
        start_html5_timer();
      }

      <span class="keyword">if</span> (s.playState === <span class="number">1</span> &amp;&amp; !s.paused) {

        allowMulti = s._iO.multiShot;

        <span class="keyword">if</span> (!allowMulti) {

          sm2._wD(fN + <span class="string">'Already playing (one-shot)'</span>, <span class="number">1</span>);

          <span class="keyword">if</span> (s.isHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-138">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-138">&#182;</a>
              </div>
              <p>go back to original position.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s.setPosition(s._iO.position);
          }

          <span class="keyword">return</span> s;

        }

        sm2._wD(fN + <span class="string">'Already playing (multi-shot)'</span>, <span class="number">1</span>);

      }</pre></div></div>
            
        </li>
        
        
        <li id="section-139">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-139">&#182;</a>
              </div>
              <p>edge case: play() with explicit URL parameter</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (options.url &amp;&amp; options.url !== s.url) {</pre></div></div>
            
        </li>
        
        
        <li id="section-140">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-140">&#182;</a>
              </div>
              <p>special case for createSound() followed by load() / play() with url; avoid double-load case.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (!s.readyState &amp;&amp; !s.isHTML5 &amp;&amp; fV === <span class="number">8</span> &amp;&amp; urlOmitted) {

          urlOmitted = <span class="literal">false</span>;

        } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-141">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-141">&#182;</a>
              </div>
              <p>load using merged options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s.load(s._iO);

        }

      }

      <span class="keyword">if</span> (!s.loaded) {

        <span class="keyword">if</span> (s.readyState === <span class="number">0</span>) {

          sm2._wD(fN + <span class="string">'Attempting to load'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-142">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-142">&#182;</a>
              </div>
              <p>try to get this sound playing ASAP</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; !sm2.html5Only) {</pre></div></div>
            
        </li>
        
        
        <li id="section-143">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-143">&#182;</a>
              </div>
              <p>flash: assign directly because setAutoPlay() increments the instanceCount</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s._iO.autoPlay = <span class="literal">true</span>;
            s.load(s._iO);

          } <span class="keyword">else</span> <span class="keyword">if</span> (s.isHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-144">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-144">&#182;</a>
              </div>
              <p>iOS needs this when recycling sounds, loading a new URL on an existing object.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s.load(s._iO);

          } <span class="keyword">else</span> {

            sm2._wD(fN + <span class="string">'Unsupported type. Exiting.'</span>);

            <span class="keyword">return</span> s;

          }</pre></div></div>
            
        </li>
        
        
        <li id="section-145">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-145">&#182;</a>
              </div>
              <p>HTML5 hack - re-set instanceOptions?</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s.instanceOptions = s._iO;

        } <span class="keyword">else</span> <span class="keyword">if</span> (s.readyState === <span class="number">2</span>) {

          sm2._wD(fN + <span class="string">'Could not load - exiting'</span>, <span class="number">2</span>);

          <span class="keyword">return</span> s;

        } <span class="keyword">else</span> {

          sm2._wD(fN + <span class="string">'Loading - attempting to play...'</span>);

        }

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-146">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-146">&#182;</a>
              </div>
              <p>&quot;play()&quot;</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(fN.substr(<span class="number">0</span>, fN.lastIndexOf(<span class="string">':'</span>)));

      }

      <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; fV === <span class="number">9</span> &amp;&amp; s.position &gt; <span class="number">0</span> &amp;&amp; s.position === s.duration) {</pre></div></div>
            
        </li>
        
        
        <li id="section-147">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-147">&#182;</a>
              </div>
              <p>flash 9 needs a position reset if play() is called while at the end of a sound.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(fN + <span class="string">'Sound at end, resetting to position: 0'</span>);
        options.position = <span class="number">0</span>;
      }

      <span class="comment">/**
       * Streams will pause when their buffer is full if they are being loaded.
       * In this case paused is true, but the song hasn't started playing yet.
       * If we just call resume() the onplay() callback will never be called.
       * So only call resume() if the position is &gt; 0.
       * Another reason is because options like volume won't have been applied yet.
       * For normal sounds, just resume.
       */</span>

      <span class="keyword">if</span> (s.paused &amp;&amp; s.position &gt;= <span class="number">0</span> &amp;&amp; (!s._iO.serverURL || s.position &gt; <span class="number">0</span>)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-148">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-148">&#182;</a>
              </div>
              <p><a href="https://gist.github.com/37b17df75cc4d7a90bf6">https://gist.github.com/37b17df75cc4d7a90bf6</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(fN + <span class="string">'Resuming from paused state'</span>, <span class="number">1</span>);
        s.resume();

      } <span class="keyword">else</span> {

        s._iO = mixin(options, s._iO);

        <span class="comment">/**
         * Preload in the event of play() with position under Flash,
         * or from/to parameters and non-RTMP case
         */</span>
        <span class="keyword">if</span> (((!s.isHTML5 &amp;&amp; s._iO.position !== <span class="literal">null</span> &amp;&amp; s._iO.position &gt; <span class="number">0</span>) || (s._iO.from !== <span class="literal">null</span> &amp;&amp; s._iO.from &gt; <span class="number">0</span>) || s._iO.to !== <span class="literal">null</span>) &amp;&amp; s.instanceCount === <span class="number">0</span> &amp;&amp; s.playState === <span class="number">0</span> &amp;&amp; !s._iO.serverURL) {

          onready = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-149">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-149">&#182;</a>
              </div>
              <p>sound &quot;canplay&quot; or onload()
re-apply position/from/to to instance options, and start playback</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s._iO = mixin(options, s._iO);
            s.play(s._iO);
          };</pre></div></div>
            
        </li>
        
        
        <li id="section-150">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-150">&#182;</a>
              </div>
              <p>HTML5 needs to at least have &quot;canplay&quot; fired before seeking.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (s.isHTML5 &amp;&amp; !s._html5_canplay) {</pre></div></div>
            
        </li>
        
        
        <li id="section-151">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-151">&#182;</a>
              </div>
              <p>this hasn&#39;t been loaded yet. load it first, and then do this again.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2._wD(fN + <span class="string">'Beginning load for non-zero offset case'</span>);

            s.load({</pre></div></div>
            
        </li>
        
        
        <li id="section-152">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-152">&#182;</a>
              </div>
              <p>note: custom HTML5-only event added for from/to implementation.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              _oncanplay: onready
            });

          } <span class="keyword">else</span> <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; !s.loaded &amp;&amp; (!s.readyState || s.readyState !== <span class="number">2</span>)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-153">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-153">&#182;</a>
              </div>
              <p>to be safe, preload the whole thing in Flash.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
            sm2._wD(fN + <span class="string">'Preloading for non-zero offset case'</span>);

            s.load({
              onload: onready
            });

          }</pre></div></div>
            
        </li>
        
        
        <li id="section-154">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-154">&#182;</a>
              </div>
              <p>otherwise, we&#39;re ready to go. re-apply local options, and continue</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          s._iO = applyFromTo();

        }</pre></div></div>
            
        </li>
        
        
        <li id="section-155">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-155">&#182;</a>
              </div>
              <p>sm2._wD(fN + &#39;Starting to play&#39;);</p>

            </div>
            
        </li>
        
        
        <li id="section-156">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-156">&#182;</a>
              </div>
              <p>increment instance counter, where enabled + supported</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (!s.instanceCount || s._iO.multiShotEvents || (s.isHTML5 &amp;&amp; s._iO.multiShot &amp;&amp; !useGlobalHTML5Audio) || (!s.isHTML5 &amp;&amp; fV &gt; <span class="number">8</span> &amp;&amp; !s.getAutoPlay())) {
          s.instanceCount++;
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-157">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-157">&#182;</a>
              </div>
              <p>if first play and onposition parameters exist, apply them now</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (s._iO.onposition &amp;&amp; s.playState === <span class="number">0</span>) {
          attachOnPosition(s);
        }

        s.playState = <span class="number">1</span>;
        s.paused = <span class="literal">false</span>;

        s.position = (s._iO.position !== _<span class="literal">undefined</span> &amp;&amp; !isNaN(s._iO.position) ? s._iO.position : <span class="number">0</span>);

        <span class="keyword">if</span> (!s.isHTML5) {
          s._iO = policyFix(loopFix(s._iO));
        }

        <span class="keyword">if</span> (s._iO.onplay &amp;&amp; _updatePlayState) {
          s._iO.onplay.apply(s);
          onplay_called = <span class="literal">true</span>;
        }

        s.setVolume(s._iO.volume, <span class="literal">true</span>);
        s.setPan(s._iO.pan, <span class="literal">true</span>);

        <span class="keyword">if</span> (s._iO.playbackRate !== <span class="number">1</span>) {
          s.setPlaybackRate(s._iO.playbackRate);
        }

        <span class="keyword">if</span> (!s.isHTML5) {

          startOK = flash._start(s.id, s._iO.loops || <span class="number">1</span>, (fV === <span class="number">9</span> ? s.position : s.position / msecScale), s._iO.multiShot || <span class="literal">false</span>);

          <span class="keyword">if</span> (fV === <span class="number">9</span> &amp;&amp; !startOK) {</pre></div></div>
            
        </li>
        
        
        <li id="section-158">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-158">&#182;</a>
              </div>
              <p>edge case: no sound hardware, or 32-channel flash ceiling hit.
applies only to Flash 9, non-NetStream/MovieStar sounds.
<a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#play%28%29">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#play%28%29</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2._wD(fN + <span class="string">'No sound hardware, or 32-sound ceiling hit'</span>, <span class="number">2</span>);
            <span class="keyword">if</span> (s._iO.onplayerror) {
              s._iO.onplayerror.apply(s);
            }

          }

        } <span class="keyword">else</span> <span class="keyword">if</span> (s.instanceCount &lt; <span class="number">2</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-159">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-159">&#182;</a>
              </div>
              <p>HTML5 single-instance case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
            start_html5_timer();

            a = s._setup_html5();

            s.setPosition(s._iO.position);

            a.play();

          } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-160">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-160">&#182;</a>
              </div>
              <p>HTML5 multi-shot case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
            sm2._wD(s.id + <span class="string">': Cloning Audio() for instance #'</span> + s.instanceCount + <span class="string">'...'</span>);

            audioClone = <span class="keyword">new</span> Audio(s._iO.url);

            onended = <span class="keyword">function</span>() {
              event.remove(audioClone, <span class="string">'ended'</span>, onended);
              s._onfinish(s);</pre></div></div>
            
        </li>
        
        
        <li id="section-161">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-161">&#182;</a>
              </div>
              <p>cleanup</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              html5Unload(audioClone);
              audioClone = <span class="literal">null</span>;
            };

            oncanplay = <span class="keyword">function</span>() {
              event.remove(audioClone, <span class="string">'canplay'</span>, oncanplay);
              <span class="keyword">try</span> {
                audioClone.currentTime = s._iO.position / msecScale;
              } <span class="keyword">catch</span>(err) {
                complain(s.id + <span class="string">': multiShot play() failed to apply position of '</span> + (s._iO.position / msecScale));
              }
              audioClone.play();
            };

            event.add(audioClone, <span class="string">'ended'</span>, onended);</pre></div></div>
            
        </li>
        
        
        <li id="section-162">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-162">&#182;</a>
              </div>
              <p>apply volume to clones, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            <span class="keyword">if</span> (s._iO.volume !== _<span class="literal">undefined</span>) {
              audioClone.volume = Math.max(<span class="number">0</span>, Math.min(<span class="number">1</span>, s._iO.volume / <span class="number">100</span>));
            }</pre></div></div>
            
        </li>
        
        
        <li id="section-163">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-163">&#182;</a>
              </div>
              <p>playing multiple muted sounds? if you do this, you&#39;re weird ;) - but let&#39;s cover it.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            <span class="keyword">if</span> (s.muted) {
              audioClone.muted = <span class="literal">true</span>;
            }

            <span class="keyword">if</span> (s._iO.position) {</pre></div></div>
            
        </li>
        
        
        <li id="section-164">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-164">&#182;</a>
              </div>
              <p>HTML5 audio can&#39;t seek before onplay() event has fired.
wait for canplay, then seek to position and start playback.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              event.add(audioClone, <span class="string">'canplay'</span>, oncanplay);
            } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-165">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-165">&#182;</a>
              </div>
              <p>begin playback at currentTime: 0</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              audioClone.play();
            }

          }

      }

      <span class="keyword">return</span> s;

    };</pre></div></div>
            
        </li>
        
        
        <li id="section-166">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-166">&#182;</a>
              </div>
              <p>just for convenience</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>.start = <span class="keyword">this</span>.play;

    <span class="comment">/**
     * Stops playing a sound (and optionally, all sounds)
     *
     * @param {boolean} bAll Optional: Whether to stop all sounds
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.stop = <span class="keyword">function</span>(bAll) {

      <span class="keyword">var</span> instanceOptions = s._iO,
          originalPosition;

      <span class="keyword">if</span> (s.playState === <span class="number">1</span>) {

        sm2._wD(s.id + <span class="string">': stop()'</span>);

        s._onbufferchange(<span class="number">0</span>);
        s._resetOnPosition(<span class="number">0</span>);
        s.paused = <span class="literal">false</span>;

        <span class="keyword">if</span> (!s.isHTML5) {
          s.playState = <span class="number">0</span>;
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-167">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-167">&#182;</a>
              </div>
              <p>remove onPosition listeners, if any</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        detachOnPosition();</pre></div></div>
            
        </li>
        
        
        <li id="section-168">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-168">&#182;</a>
              </div>
              <p>and &quot;to&quot; position, if set</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (instanceOptions.to) {
          s.clearOnPosition(instanceOptions.to);
        }

        <span class="keyword">if</span> (!s.isHTML5) {

          flash._stop(s.id, bAll);</pre></div></div>
            
        </li>
        
        
        <li id="section-169">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-169">&#182;</a>
              </div>
              <p>hack for netStream: just unload</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (instanceOptions.serverURL) {
            s.unload();
          }

        } <span class="keyword">else</span> <span class="keyword">if</span> (s._a) {

            originalPosition = s.position;</pre></div></div>
            
        </li>
        
        
        <li id="section-170">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-170">&#182;</a>
              </div>
              <p>act like Flash, though</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s.setPosition(<span class="number">0</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-171">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-171">&#182;</a>
              </div>
              <p>hack: reflect old position for onstop() (also like Flash)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s.position = originalPosition;</pre></div></div>
            
        </li>
        
        
        <li id="section-172">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-172">&#182;</a>
              </div>
              <p>html5 has no stop()
NOTE: pausing means iOS requires interaction to resume.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s._a.pause();

            s.playState = <span class="number">0</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-173">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-173">&#182;</a>
              </div>
              <p>and update UI</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s._onTimer();

            stop_html5_timer();

          }

        s.instanceCount = <span class="number">0</span>;
        s._iO = {};

        <span class="keyword">if</span> (instanceOptions.onstop) {
          instanceOptions.onstop.apply(s);
        }

      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Undocumented/internal: Sets autoPlay for RTMP.
     *
     * @param {boolean} autoPlay state
     */</span>

    <span class="keyword">this</span>.setAutoPlay = <span class="keyword">function</span>(autoPlay) {

      sm2._wD(s.id + <span class="string">': Autoplay turned '</span> + (autoPlay ? <span class="string">'on'</span> : <span class="string">'off'</span>));
      s._iO.autoPlay = autoPlay;

      <span class="keyword">if</span> (!s.isHTML5) {
        flash._setAutoPlay(s.id, autoPlay);
        <span class="keyword">if</span> (autoPlay) {</pre></div></div>
            
        </li>
        
        
        <li id="section-174">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-174">&#182;</a>
              </div>
              <p>only increment the instanceCount if the sound isn&#39;t loaded (TODO: verify RTMP)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (!s.instanceCount &amp;&amp; s.readyState === <span class="number">1</span>) {
            s.instanceCount++;
            sm2._wD(s.id + <span class="string">': Incremented instance count to '</span> + s.instanceCount);
          }
        }
      }

    };

    <span class="comment">/**
     * Undocumented/internal: Returns the autoPlay boolean.
     *
     * @return {boolean} The current autoPlay value
     */</span>

    <span class="keyword">this</span>.getAutoPlay = <span class="keyword">function</span>() {

      <span class="keyword">return</span> s._iO.autoPlay;

    };

    <span class="comment">/**
     * Sets the playback rate of a sound (HTML5-only.)
     *
     * @param {number} playbackRate (+/-)
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.setPlaybackRate = <span class="keyword">function</span>(playbackRate) {</pre></div></div>
            
        </li>
        
        
        <li id="section-175">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-175">&#182;</a>
              </div>
              <p>Per Mozilla, limit acceptable values to prevent playback from stopping (unless allowOverride is truthy.)
<a href="https://developer.mozilla.org/en-US/Apps/Build/Audio_and_video_delivery/WebAudio_playbackRate_explained">https://developer.mozilla.org/en-US/Apps/Build/Audio_and_video_delivery/WebAudio_playbackRate_explained</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">var</span> normalizedRate = Math.max(<span class="number">0.5</span>, Math.min(<span class="number">4</span>, playbackRate));</pre></div></div>
            
        </li>
        
        
        <li id="section-176">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-176">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (normalizedRate !== playbackRate) {
        sm2._wD(s.id + <span class="string">': setPlaybackRate('</span> + playbackRate + <span class="string">'): limiting rate to '</span> + normalizedRate, <span class="number">2</span>);
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-177">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-177">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (s.isHTML5) {
        <span class="keyword">try</span> {
          s._iO.playbackRate = normalizedRate;
          s._a.playbackRate = normalizedRate;
        } <span class="keyword">catch</span>(e) {
          sm2._wD(s.id + <span class="string">': setPlaybackRate('</span> + normalizedRate + <span class="string">') failed: '</span> + e.message, <span class="number">2</span>);
        }
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Sets the position of a sound.
     *
     * @param {number} nMsecOffset Position (milliseconds)
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.setPosition = <span class="keyword">function</span>(nMsecOffset) {

      <span class="keyword">if</span> (nMsecOffset === _<span class="literal">undefined</span>) {
        nMsecOffset = <span class="number">0</span>;
      }

      <span class="keyword">var</span> position, position1K,</pre></div></div>
            
        </li>
        
        
        <li id="section-178">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-178">&#182;</a>
              </div>
              <p>Use the duration from the instance options, if we don&#39;t have a track duration yet.
position &gt;= 0 and &lt;= current available (loaded) duration</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          offset = (s.isHTML5 ? Math.max(nMsecOffset, <span class="number">0</span>) : Math.min(s.duration || s._iO.duration, Math.max(nMsecOffset, <span class="number">0</span>)));

      s.position = offset;
      position1K = s.position / msecScale;
      s._resetOnPosition(s.position);
      s._iO.position = offset;

      <span class="keyword">if</span> (!s.isHTML5) {

        position = (fV === <span class="number">9</span> ? s.position : position1K);

        <span class="keyword">if</span> (s.readyState &amp;&amp; s.readyState !== <span class="number">2</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-179">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-179">&#182;</a>
              </div>
              <p>if paused or not playing, will not resume (by playing)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          flash._setPosition(s.id, position, (s.paused || !s.playState), s._iO.multiShot);
        }

      } <span class="keyword">else</span> <span class="keyword">if</span> (s._a) {</pre></div></div>
            
        </li>
        
        
        <li id="section-180">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-180">&#182;</a>
              </div>
              <p>Set the position in the canplay handler if the sound is not ready yet</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (s._html5_canplay) {

          <span class="keyword">if</span> (s._a.currentTime.toFixed(<span class="number">3</span>) !== position1K.toFixed(<span class="number">3</span>)) {

            <span class="comment">/**
             * DOM/JS errors/exceptions to watch out for:
             * if seek is beyond (loaded?) position, "DOM exception 11"
             * "INDEX_SIZE_ERR": DOM exception 1
             */</span>
            sm2._wD(s.id + <span class="string">': setPosition('</span> + position1K + <span class="string">')'</span>);

            <span class="keyword">try</span> {
              s._a.currentTime = position1K;
              <span class="keyword">if</span> (s.playState === <span class="number">0</span> || s.paused) {</pre></div></div>
            
        </li>
        
        
        <li id="section-181">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-181">&#182;</a>
              </div>
              <p>allow seek without auto-play/resume</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>                s._a.pause();
              }
            } <span class="keyword">catch</span>(e) {
              sm2._wD(s.id + <span class="string">': setPosition('</span> + position1K + <span class="string">') failed: '</span> + e.message, <span class="number">2</span>);
            }

          }

        } <span class="keyword">else</span> <span class="keyword">if</span> (position1K) {</pre></div></div>
            
        </li>
        
        
        <li id="section-182">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-182">&#182;</a>
              </div>
              <p>warn on non-zero seek attempts</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2._wD(s.id + <span class="string">': setPosition('</span> + position1K + <span class="string">'): Cannot seek yet, sound not ready'</span>, <span class="number">2</span>);
          <span class="keyword">return</span> s;

        }

        <span class="keyword">if</span> (s.paused) {</pre></div></div>
            
        </li>
        
        
        <li id="section-183">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-183">&#182;</a>
              </div>
              <p>if paused, refresh UI right away by forcing update</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s._onTimer(<span class="literal">true</span>);

        }

      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Pauses sound playback.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.pause = <span class="keyword">function</span>(_bCallFlash) {

      <span class="keyword">if</span> (s.paused || (s.playState === <span class="number">0</span> &amp;&amp; s.readyState !== <span class="number">1</span>)) <span class="keyword">return</span> s;

      sm2._wD(s.id + <span class="string">': pause()'</span>);
      s.paused = <span class="literal">true</span>;

      <span class="keyword">if</span> (!s.isHTML5) {
        <span class="keyword">if</span> (_bCallFlash || _bCallFlash === _<span class="literal">undefined</span>) {
          flash._pause(s.id, s._iO.multiShot);
        }
      } <span class="keyword">else</span> {
        s._setup_html5().pause();
        stop_html5_timer();
      }

      <span class="keyword">if</span> (s._iO.onpause) {
        s._iO.onpause.apply(s);
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Resumes sound playback.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="comment">/**
     * When auto-loaded streams pause on buffer full they have a playState of 0.
     * We need to make sure that the playState is set to 1 when these streams "resume".
     * When a paused stream is resumed, we need to trigger the onplay() callback if it
     * hasn't been called already. In this case since the sound is being played for the
     * first time, I think it's more appropriate to call onplay() rather than onresume().
     */</span>

    <span class="keyword">this</span>.resume = <span class="keyword">function</span>() {

      <span class="keyword">var</span> instanceOptions = s._iO;

      <span class="keyword">if</span> (!s.paused) <span class="keyword">return</span> s;

      sm2._wD(s.id + <span class="string">': resume()'</span>);
      s.paused = <span class="literal">false</span>;
      s.playState = <span class="number">1</span>;

      <span class="keyword">if</span> (!s.isHTML5) {

        <span class="keyword">if</span> (instanceOptions.isMovieStar &amp;&amp; !instanceOptions.serverURL) {</pre></div></div>
            
        </li>
        
        
        <li id="section-184">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-184">&#182;</a>
              </div>
              <p>Bizarre Webkit bug (Chrome reported via 8tracks.com dudes): AAC content paused for 30+ seconds(?) will not resume without a reposition.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s.setPosition(s.position);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-185">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-185">&#182;</a>
              </div>
              <p>flash method is toggle-based (pause/resume)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        flash._pause(s.id, instanceOptions.multiShot);

      } <span class="keyword">else</span> {

        s._setup_html5().play();
        start_html5_timer();

      }

      <span class="keyword">if</span> (!onplay_called &amp;&amp; instanceOptions.onplay) {

        instanceOptions.onplay.apply(s);
        onplay_called = <span class="literal">true</span>;

      } <span class="keyword">else</span> <span class="keyword">if</span> (instanceOptions.onresume) {

        instanceOptions.onresume.apply(s);

      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Toggles sound playback.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.togglePause = <span class="keyword">function</span>() {

      sm2._wD(s.id + <span class="string">': togglePause()'</span>);

      <span class="keyword">if</span> (s.playState === <span class="number">0</span>) {
        s.play({
          position: (fV === <span class="number">9</span> &amp;&amp; !s.isHTML5 ? s.position : s.position / msecScale)
        });
        <span class="keyword">return</span> s;
      }

      <span class="keyword">if</span> (s.paused) {
        s.resume();
      } <span class="keyword">else</span> {
        s.pause();
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Sets the panning (L-R) effect.
     *
     * @param {number} nPan The pan value (-100 to 100)
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.setPan = <span class="keyword">function</span>(nPan, bInstanceOnly) {

      <span class="keyword">if</span> (nPan === _<span class="literal">undefined</span>) {
        nPan = <span class="number">0</span>;
      }

      <span class="keyword">if</span> (bInstanceOnly === _<span class="literal">undefined</span>) {
        bInstanceOnly = <span class="literal">false</span>;
      }

      <span class="keyword">if</span> (!s.isHTML5) {
        flash._setPan(s.id, nPan);
      } <span class="comment">// else { no HTML5 pan? }</span>

      s._iO.pan = nPan;

      <span class="keyword">if</span> (!bInstanceOnly) {
        s.pan = nPan;
        s.options.pan = nPan;
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Sets the volume.
     *
     * @param {number} nVol The volume value (0 to 100)
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.setVolume = <span class="keyword">function</span>(nVol, _bInstanceOnly) {

      <span class="comment">/**
       * Note: Setting volume has no effect on iOS "special snowflake" devices.
       * Hardware volume control overrides software, and volume
       * will always return 1 per Apple docs. (iOS 4 + 5.)
       * http://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/AddingSoundtoCanvasAnimations/AddingSoundtoCanvasAnimations.html
       */</span>

      <span class="keyword">if</span> (nVol === _<span class="literal">undefined</span>) {
        nVol = <span class="number">100</span>;
      }

      <span class="keyword">if</span> (_bInstanceOnly === _<span class="literal">undefined</span>) {
        _bInstanceOnly = <span class="literal">false</span>;
      }

      <span class="keyword">if</span> (!s.isHTML5) {

        flash._setVolume(s.id, (sm2.muted &amp;&amp; !s.muted) || s.muted ? <span class="number">0</span> : nVol);

      } <span class="keyword">else</span> <span class="keyword">if</span> (s._a) {

        <span class="keyword">if</span> (sm2.muted &amp;&amp; !s.muted) {
          s.muted = <span class="literal">true</span>;
          s._a.muted = <span class="literal">true</span>;
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-186">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-186">&#182;</a>
              </div>
              <p>valid range for native HTML5 Audio(): 0-1</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        s._a.volume = Math.max(<span class="number">0</span>, Math.min(<span class="number">1</span>, nVol / <span class="number">100</span>));

      }

      s._iO.volume = nVol;

      <span class="keyword">if</span> (!_bInstanceOnly) {
        s.volume = nVol;
        s.options.volume = nVol;
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Mutes the sound.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.mute = <span class="keyword">function</span>() {

      s.muted = <span class="literal">true</span>;

      <span class="keyword">if</span> (!s.isHTML5) {
        flash._setVolume(s.id, <span class="number">0</span>);
      } <span class="keyword">else</span> <span class="keyword">if</span> (s._a) {
        s._a.muted = <span class="literal">true</span>;
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Unmutes the sound.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.unmute = <span class="keyword">function</span>() {

      s.muted = <span class="literal">false</span>;
      <span class="keyword">var</span> hasIO = (s._iO.volume !== _<span class="literal">undefined</span>);

      <span class="keyword">if</span> (!s.isHTML5) {
        flash._setVolume(s.id, hasIO ? s._iO.volume : s.options.volume);
      } <span class="keyword">else</span> <span class="keyword">if</span> (s._a) {
        s._a.muted = <span class="literal">false</span>;
      }

      <span class="keyword">return</span> s;

    };

    <span class="comment">/**
     * Toggles the muted state of a sound.
     *
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.toggleMute = <span class="keyword">function</span>() {

      <span class="keyword">return</span> (s.muted ? s.unmute() : s.mute());

    };

    <span class="comment">/**
     * Registers a callback to be fired when a sound reaches a given position during playback.
     *
     * @param {number} nPosition The position to watch for
     * @param {function} oMethod The relevant callback to fire
     * @param {object} oScope Optional: The scope to apply the callback to
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.onPosition = <span class="keyword">function</span>(nPosition, oMethod, oScope) {</pre></div></div>
            
        </li>
        
        
        <li id="section-187">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-187">&#182;</a>
              </div>
              <p>TODO: basic dupe checking?</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      onPositionItems.push({
        position: parseInt(nPosition, <span class="number">10</span>),
        method: oMethod,
        scope: (oScope !== _<span class="literal">undefined</span> ? oScope : s),
        fired: <span class="literal">false</span>
      });

      <span class="keyword">return</span> s;

    };</pre></div></div>
            
        </li>
        
        
        <li id="section-188">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-188">&#182;</a>
              </div>
              <p>legacy/backwards-compability: lower-case method name</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>.onposition = <span class="keyword">this</span>.onPosition;

    <span class="comment">/**
     * Removes registered callback(s) from a sound, by position and/or callback.
     *
     * @param {number} nPosition The position to clear callback(s) for
     * @param {function} oMethod Optional: Identify one callback to be removed when multiple listeners exist for one position
     * @return {SMSound} The SMSound object
     */</span>

    <span class="keyword">this</span>.clearOnPosition = <span class="keyword">function</span>(nPosition, oMethod) {

      <span class="keyword">var</span> i;

      nPosition = parseInt(nPosition, <span class="number">10</span>);

      <span class="keyword">if</span> (isNaN(nPosition)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-189">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-189">&#182;</a>
              </div>
              <p>safety check</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">return</span>;
      }

      <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; onPositionItems.length; i++) {

        <span class="keyword">if</span> (nPosition === onPositionItems[i].position) {</pre></div></div>
            
        </li>
        
        
        <li id="section-190">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-190">&#182;</a>
              </div>
              <p>remove this item if no method was specified, or, if the method matches</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          <span class="keyword">if</span> (!oMethod || (oMethod === onPositionItems[i].method)) {

            <span class="keyword">if</span> (onPositionItems[i].fired) {</pre></div></div>
            
        </li>
        
        
        <li id="section-191">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-191">&#182;</a>
              </div>
              <p>decrement &quot;fired&quot; counter, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              onPositionFired--;
            }

            onPositionItems.splice(i, <span class="number">1</span>);

          }

        }

      }

    };

    <span class="keyword">this</span>._processOnPosition = <span class="keyword">function</span>() {

      <span class="keyword">var</span> i, item, j = onPositionItems.length;

      <span class="keyword">if</span> (!j || !s.playState || onPositionFired &gt;= j) <span class="keyword">return</span> <span class="literal">false</span>;

      <span class="keyword">for</span> (i = j - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {

        item = onPositionItems[i];

        <span class="keyword">if</span> (!item.fired &amp;&amp; s.position &gt;= item.position) {

          item.fired = <span class="literal">true</span>;
          onPositionFired++;
          item.method.apply(item.scope, [item.position]);</pre></div></div>
            
        </li>
        
        
        <li id="section-192">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-192">&#182;</a>
              </div>
              <p> reset j -- onPositionItems.length can be changed in the item callback above... occasionally breaking the loop.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          j = onPositionItems.length;

        }

      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    <span class="keyword">this</span>._resetOnPosition = <span class="keyword">function</span>(nPosition) {</pre></div></div>
            
        </li>
        
        
        <li id="section-193">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-193">&#182;</a>
              </div>
              <p>reset &quot;fired&quot; for items interested in this position</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">var</span> i, item, j = onPositionItems.length;

      <span class="keyword">if</span> (!j) <span class="keyword">return</span> <span class="literal">false</span>;

      <span class="keyword">for</span> (i = j - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {

        item = onPositionItems[i];

        <span class="keyword">if</span> (item.fired &amp;&amp; nPosition &lt;= item.position) {
          item.fired = <span class="literal">false</span>;
          onPositionFired--;
        }

      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    <span class="comment">/**
     * SMSound() private internals
     * --------------------------------
     */</span>

    applyFromTo = <span class="keyword">function</span>() {

      <span class="keyword">var</span> instanceOptions = s._iO,
          f = instanceOptions.from,
          t = instanceOptions.to,
          start, end;

      end = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-194">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-194">&#182;</a>
              </div>
              <p>end has been reached.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2._wD(s.id + <span class="string">': "To" time of '</span> + t + <span class="string">' reached.'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-195">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-195">&#182;</a>
              </div>
              <p>detach listener</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        s.clearOnPosition(t, end);</pre></div></div>
            
        </li>
        
        
        <li id="section-196">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-196">&#182;</a>
              </div>
              <p>stop should clear this, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        s.stop();

      };

      start = <span class="keyword">function</span>() {

        sm2._wD(s.id + <span class="string">': Playing "from" '</span> + f);</pre></div></div>
            
        </li>
        
        
        <li id="section-197">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-197">&#182;</a>
              </div>
              <p>add listener for end</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (t !== <span class="literal">null</span> &amp;&amp; !isNaN(t)) {
          s.onPosition(t, end);
        }

      };

      <span class="keyword">if</span> (f !== <span class="literal">null</span> &amp;&amp; !isNaN(f)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-198">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-198">&#182;</a>
              </div>
              <p>apply to instance options, guaranteeing correct start position.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        instanceOptions.position = f;</pre></div></div>
            
        </li>
        
        
        <li id="section-199">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-199">&#182;</a>
              </div>
              <p>multiShot timing can&#39;t be tracked, so prevent that.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        instanceOptions.multiShot = <span class="literal">false</span>;

        start();

      }</pre></div></div>
            
        </li>
        
        
        <li id="section-200">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-200">&#182;</a>
              </div>
              <p>return updated instanceOptions including starting position</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">return</span> instanceOptions;

    };

    attachOnPosition = <span class="keyword">function</span>() {

      <span class="keyword">var</span> item,
          op = s._iO.onposition;</pre></div></div>
            
        </li>
        
        
        <li id="section-201">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-201">&#182;</a>
              </div>
              <p>attach onposition things, if any, now.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (op) {

        <span class="keyword">for</span> (item <span class="keyword">in</span> op) {
          <span class="keyword">if</span> (op.hasOwnProperty(item)) {
            s.onPosition(parseInt(item, <span class="number">10</span>), op[item]);
          }
        }

      }

    };

    detachOnPosition = <span class="keyword">function</span>() {

      <span class="keyword">var</span> item,
          op = s._iO.onposition;</pre></div></div>
            
        </li>
        
        
        <li id="section-202">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-202">&#182;</a>
              </div>
              <p>detach any onposition()-style listeners.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (op) {

        <span class="keyword">for</span> (item <span class="keyword">in</span> op) {
          <span class="keyword">if</span> (op.hasOwnProperty(item)) {
            s.clearOnPosition(parseInt(item, <span class="number">10</span>));
          }
        }

      }

    };

    start_html5_timer = <span class="keyword">function</span>() {

      <span class="keyword">if</span> (s.isHTML5) {
        startTimer(s);
      }

    };

    stop_html5_timer = <span class="keyword">function</span>() {

      <span class="keyword">if</span> (s.isHTML5) {
        stopTimer(s);
      }

    };

    resetProperties = <span class="keyword">function</span>(retainPosition) {

      <span class="keyword">if</span> (!retainPosition) {
        onPositionItems = [];
        onPositionFired = <span class="number">0</span>;
      }

      onplay_called = <span class="literal">false</span>;

      s._hasTimer = <span class="literal">null</span>;
      s._a = <span class="literal">null</span>;
      s._html5_canplay = <span class="literal">false</span>;
      s.bytesLoaded = <span class="literal">null</span>;
      s.bytesTotal = <span class="literal">null</span>;
      s.duration = (s._iO &amp;&amp; s._iO.duration ? s._iO.duration : <span class="literal">null</span>);
      s.durationEstimate = <span class="literal">null</span>;
      s.buffered = [];</pre></div></div>
            
        </li>
        
        
        <li id="section-203">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-203">&#182;</a>
              </div>
              <p>legacy: 1D array</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s.eqData = [];

      s.eqData.left = [];
      s.eqData.right = [];

      s.failures = <span class="number">0</span>;
      s.isBuffering = <span class="literal">false</span>;
      s.instanceOptions = {};
      s.instanceCount = <span class="number">0</span>;
      s.loaded = <span class="literal">false</span>;
      s.metadata = {};</pre></div></div>
            
        </li>
        
        
        <li id="section-204">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-204">&#182;</a>
              </div>
              <p>0 = uninitialised, 1 = loading, 2 = failed/error, 3 = loaded/success</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s.readyState = <span class="number">0</span>;

      s.muted = <span class="literal">false</span>;
      s.paused = <span class="literal">false</span>;

      s.peakData = {
        left: <span class="number">0</span>,
        right: <span class="number">0</span>
      };

      s.waveformData = {
        left: [],
        right: []
      };

      s.playState = <span class="number">0</span>;
      s.position = <span class="literal">null</span>;

      s.id3 = {};

    };

    resetProperties();

    <span class="comment">/**
     * Pseudo-private SMSound internals
     * --------------------------------
     */</span>

    <span class="keyword">this</span>._onTimer = <span class="keyword">function</span>(bForce) {

      <span class="comment">/**
       * HTML5-only _whileplaying() etc.
       * called from both HTML5 native events, and polling/interval-based timers
       * mimics flash and fires only when time/duration change, so as to be polling-friendly
       */</span>

      <span class="keyword">var</span> duration, isNew = <span class="literal">false</span>, time, x = {};

      <span class="keyword">if</span> (s._hasTimer || bForce) {</pre></div></div>
            
        </li>
        
        
        <li id="section-205">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-205">&#182;</a>
              </div>
              <p>TODO: May not need to track readyState (1 = loading)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        <span class="keyword">if</span> (s._a &amp;&amp; (bForce || ((s.playState &gt; <span class="number">0</span> || s.readyState === <span class="number">1</span>) &amp;&amp; !s.paused))) {

          duration = s._get_html5_duration();

          <span class="keyword">if</span> (duration !== lastHTML5State.duration) {

            lastHTML5State.duration = duration;
            s.duration = duration;
            isNew = <span class="literal">true</span>;

          }</pre></div></div>
            
        </li>
        
        
        <li id="section-206">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-206">&#182;</a>
              </div>
              <p>TODO: investigate why this goes wack if not set/re-set each time.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s.durationEstimate = s.duration;

          time = (s._a.currentTime * msecScale || <span class="number">0</span>);

          <span class="keyword">if</span> (time !== lastHTML5State.time) {

            lastHTML5State.time = time;
            isNew = <span class="literal">true</span>;

          }

          <span class="keyword">if</span> (isNew || bForce) {

            s._whileplaying(time, x, x, x, x);

          }

        }<span class="comment">/* else {</pre></div></div>
            
        </li>
        
        
        <li id="section-207">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-207">&#182;</a>
              </div>
              <p>sm2._wD(&#39;_onTimer: Warn for &quot;&#39;+s.id+&#39;&quot;: &#39;+(!s._a?&#39;Could not find element. &#39;:&#39;&#39;)+(s.playState === 0?&#39;playState bad, 0?&#39;:&#39;playState = &#39;+s.playState+&#39;, OK&#39;));</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          return false;

        }*/

      }

      return isNew;

    };

    this._get_html5_duration = function() {

      var instanceOptions = s._iO,</pre></div></div>
            
        </li>
        
        
        <li id="section-208">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-208">&#182;</a>
              </div>
              <p>if audio object exists, use its duration - else, instance option duration (if provided - it&#39;s a hack, really, and should be retired) OR null</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          d = (s._a &amp;&amp; s._a.duration ? s._a.duration * msecScale : (instanceOptions &amp;&amp; instanceOptions.duration ? instanceOptions.duration : <span class="literal">null</span>)),
          result = (d &amp;&amp; !isNaN(d) &amp;&amp; d !== <span class="literal">Infinity</span> ? d : <span class="literal">null</span>);

      <span class="keyword">return</span> result;

    };

    <span class="keyword">this</span>._apply_loop = <span class="keyword">function</span>(a, nLoops) {

      <span class="comment">/**
       * boolean instead of "loop", for webkit? - spec says string. http://www.w3.org/TR/html-markup/audio.html#audio.attrs.loop
       * note that loop is either off or infinite under HTML5, unlike Flash which allows arbitrary loop counts to be specified.
       */</span></pre></div></div>
            
        </li>
        
        
        <li id="section-209">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-209">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!a.loop &amp;&amp; nLoops &gt; <span class="number">1</span>) {
        sm2._wD(<span class="string">'Note: Native HTML5 looping is infinite.'</span>, <span class="number">1</span>);
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-210">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-210">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      a.loop = (nLoops &gt; <span class="number">1</span> ? <span class="string">'loop'</span> : <span class="string">''</span>);

    };

    <span class="keyword">this</span>._setup_html5 = <span class="keyword">function</span>(options) {

      <span class="keyword">var</span> instanceOptions = mixin(s._iO, options),
          a = useGlobalHTML5Audio ? globalHTML5Audio : s._a,
          dURL = decodeURI(instanceOptions.url),
          sameURL;

      <span class="comment">/**
       * "First things first, I, Poppa..." (reset the previous state of the old sound, if playing)
       * Fixes case with devices that can only play one sound at a time
       * Otherwise, other sounds in mid-play will be terminated without warning and in a stuck state
       */</span>

      <span class="keyword">if</span> (useGlobalHTML5Audio) {

        <span class="keyword">if</span> (dURL === decodeURI(lastGlobalHTML5URL)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-211">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-211">&#182;</a>
              </div>
              <p>global HTML5 audio: re-use of URL</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sameURL = <span class="literal">true</span>;
        }

      } <span class="keyword">else</span> <span class="keyword">if</span> (dURL === decodeURI(lastURL)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-212">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-212">&#182;</a>
              </div>
              <p>options URL is the same as the &quot;last&quot; URL, and we used (loaded) it</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sameURL = <span class="literal">true</span>;

      }

      <span class="keyword">if</span> (a) {

        <span class="keyword">if</span> (a._s) {

          <span class="keyword">if</span> (useGlobalHTML5Audio) {

            <span class="keyword">if</span> (a._s &amp;&amp; a._s.playState &amp;&amp; !sameURL) {</pre></div></div>
            
        </li>
        
        
        <li id="section-213">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-213">&#182;</a>
              </div>
              <p>global HTML5 audio case, and loading a new URL. stop the currently-playing one.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              a._s.stop();

            }

          } <span class="keyword">else</span> <span class="keyword">if</span> (!useGlobalHTML5Audio &amp;&amp; dURL === decodeURI(lastURL)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-214">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-214">&#182;</a>
              </div>
              <p>non-global HTML5 reuse case: same url, ignore request</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s._apply_loop(a, instanceOptions.loops);

            <span class="keyword">return</span> a;

          }

        }

        <span class="keyword">if</span> (!sameURL) {</pre></div></div>
            
        </li>
        
        
        <li id="section-215">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-215">&#182;</a>
              </div>
              <p>don&#39;t retain onPosition() stuff with new URLs.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          <span class="keyword">if</span> (lastURL) {
            resetProperties(<span class="literal">false</span>);
          }</pre></div></div>
            
        </li>
        
        
        <li id="section-216">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-216">&#182;</a>
              </div>
              <p>assign new HTML5 URL</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          a.src = instanceOptions.url;

          s.url = instanceOptions.url;

          lastURL = instanceOptions.url;

          lastGlobalHTML5URL = instanceOptions.url;

          a._called_load = <span class="literal">false</span>;

        }

      } <span class="keyword">else</span> {

        <span class="keyword">if</span> (instanceOptions.autoLoad || instanceOptions.autoPlay) {

          s._a = <span class="keyword">new</span> Audio(instanceOptions.url);
          s._a.load();

        } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-217">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-217">&#182;</a>
              </div>
              <p>null for stupid Opera 9.64 case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s._a = (isOpera &amp;&amp; opera.version() &lt; <span class="number">10</span> ? <span class="keyword">new</span> Audio(<span class="literal">null</span>) : <span class="keyword">new</span> Audio());

        }</pre></div></div>
            
        </li>
        
        
        <li id="section-218">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-218">&#182;</a>
              </div>
              <p>assign local reference</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        a = s._a;

        a._called_load = <span class="literal">false</span>;

        <span class="keyword">if</span> (useGlobalHTML5Audio) {

          globalHTML5Audio = a;

        }

      }

      s.isHTML5 = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-219">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-219">&#182;</a>
              </div>
              <p>store a ref on the track</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s._a = a;</pre></div></div>
            
        </li>
        
        
        <li id="section-220">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-220">&#182;</a>
              </div>
              <p>store a ref on the audio</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      a._s = s;

      add_html5_events();

      s._apply_loop(a, instanceOptions.loops);

      <span class="keyword">if</span> (instanceOptions.autoLoad || instanceOptions.autoPlay) {

        s.load();

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-221">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-221">&#182;</a>
              </div>
              <p>early HTML5 implementation (non-standard)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        a.autobuffer = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-222">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-222">&#182;</a>
              </div>
              <p>standard (&#39;none&#39; is also an option.)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        a.preload = <span class="string">'auto'</span>;

      }

      <span class="keyword">return</span> a;

    };

    add_html5_events = <span class="keyword">function</span>() {

      <span class="keyword">if</span> (s._a._added_events) <span class="keyword">return</span> <span class="literal">false</span>;

      <span class="keyword">var</span> f;

      <span class="function"><span class="keyword">function</span> <span class="title">add</span><span class="params">(oEvt, oFn, bCapture)</span> {</span>
        <span class="keyword">return</span> s._a ? s._a.addEventListener(oEvt, oFn, bCapture || <span class="literal">false</span>) : <span class="literal">null</span>;
      }

      s._a._added_events = <span class="literal">true</span>;

      <span class="keyword">for</span> (f <span class="keyword">in</span> html5_events) {
        <span class="keyword">if</span> (html5_events.hasOwnProperty(f)) {
          add(f, html5_events[f]);
        }
      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    remove_html5_events = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-223">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-223">&#182;</a>
              </div>
              <p>Remove event listeners</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">var</span> f;

      <span class="function"><span class="keyword">function</span> <span class="title">remove</span><span class="params">(oEvt, oFn, bCapture)</span> {</span>
        <span class="keyword">return</span> (s._a ? s._a.removeEventListener(oEvt, oFn, bCapture || <span class="literal">false</span>) : <span class="literal">null</span>);
      }

      sm2._wD(s.id + <span class="string">': Removing event listeners'</span>);
      s._a._added_events = <span class="literal">false</span>;

      <span class="keyword">for</span> (f <span class="keyword">in</span> html5_events) {
        <span class="keyword">if</span> (html5_events.hasOwnProperty(f)) {
          remove(f, html5_events[f]);
        }
      }

    };

    <span class="comment">/**
     * Pseudo-private event internals
     * ------------------------------
     */</span>

    <span class="keyword">this</span>._onload = <span class="keyword">function</span>(nSuccess) {

      <span class="keyword">var</span> fN,</pre></div></div>
            
        </li>
        
        
        <li id="section-224">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-224">&#182;</a>
              </div>
              <p>check for duration to prevent false positives from flash 8 when loading from cache.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          loadOK = !!nSuccess || (!s.isHTML5 &amp;&amp; fV === <span class="number">8</span> &amp;&amp; s.duration);</pre></div></div>
            
        </li>
        
        
        <li id="section-225">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-225">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      fN = s.id + <span class="string">': '</span>;
      sm2._wD(fN + (loadOK ? <span class="string">'onload()'</span> : <span class="string">'Failed to load / invalid sound?'</span> + (!s.duration ? <span class="string">' Zero-length duration reported.'</span> : <span class="string">' -'</span>) + <span class="string">' ('</span> + s.url + <span class="string">')'</span>), (loadOK ? <span class="number">1</span> : <span class="number">2</span>));

      <span class="keyword">if</span> (!loadOK &amp;&amp; !s.isHTML5) {
        <span class="keyword">if</span> (sm2.sandbox.noRemote === <span class="literal">true</span>) {
          sm2._wD(fN + str(<span class="string">'noNet'</span>), <span class="number">1</span>);
        }
        <span class="keyword">if</span> (sm2.sandbox.noLocal === <span class="literal">true</span>) {
          sm2._wD(fN + str(<span class="string">'noLocal'</span>), <span class="number">1</span>);
        }
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-226">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-226">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      s.loaded = loadOK;
      s.readyState = (loadOK ? <span class="number">3</span> : <span class="number">2</span>);
      s._onbufferchange(<span class="number">0</span>);

      <span class="keyword">if</span> (!loadOK &amp;&amp; !s.isHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-227">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-227">&#182;</a>
              </div>
              <p>note: no error code from Flash.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        s._onerror();
      }

      <span class="keyword">if</span> (s._iO.onload) {
        wrapCallback(s, <span class="keyword">function</span>() {
          s._iO.onload.apply(s, [loadOK]);
        });
      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    <span class="keyword">this</span>._onerror = <span class="keyword">function</span>(errorCode, description) {</pre></div></div>
            
        </li>
        
        
        <li id="section-228">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-228">&#182;</a>
              </div>
              <p><a href="https://html.spec.whatwg.org/multipage/embedded-content.html#error-codes">https://html.spec.whatwg.org/multipage/embedded-content.html#error-codes</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (s._iO.onerror) {
        wrapCallback(s, <span class="keyword">function</span>() {
          s._iO.onerror.apply(s, [errorCode, description]);
        });
      }

    };

    <span class="keyword">this</span>._onbufferchange = <span class="keyword">function</span>(nIsBuffering) {</pre></div></div>
            
        </li>
        
        
        <li id="section-229">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-229">&#182;</a>
              </div>
              <p>ignore if not playing</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (s.playState === <span class="number">0</span>) <span class="keyword">return</span> <span class="literal">false</span>;

      <span class="keyword">if</span> ((nIsBuffering &amp;&amp; s.isBuffering) || (!nIsBuffering &amp;&amp; !s.isBuffering)) <span class="keyword">return</span> <span class="literal">false</span>;

      s.isBuffering = (nIsBuffering === <span class="number">1</span>);

      <span class="keyword">if</span> (s._iO.onbufferchange) {
        sm2._wD(s.id + <span class="string">': Buffer state change: '</span> + nIsBuffering);
        s._iO.onbufferchange.apply(s, [nIsBuffering]);
      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    <span class="comment">/**
     * Playback may have stopped due to buffering, or related reason.
     * This state can be encountered on iOS &lt; 6 when auto-play is blocked.
     */</span>

    <span class="keyword">this</span>._onsuspend = <span class="keyword">function</span>() {

      <span class="keyword">if</span> (s._iO.onsuspend) {
        sm2._wD(s.id + <span class="string">': Playback suspended'</span>);
        s._iO.onsuspend.apply(s);
      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    <span class="comment">/**
     * flash 9/movieStar + RTMP-only method, should fire only once at most
     * at this point we just recreate failed sounds rather than trying to reconnect
     */</span>

    <span class="keyword">this</span>._onfailure = <span class="keyword">function</span>(msg, level, code) {

      s.failures++;
      sm2._wD(s.id + <span class="string">': Failure ('</span> + s.failures + <span class="string">'): '</span> + msg);

      <span class="keyword">if</span> (s._iO.onfailure &amp;&amp; s.failures === <span class="number">1</span>) {
        s._iO.onfailure(msg, level, code);
      } <span class="keyword">else</span> {
        sm2._wD(s.id + <span class="string">': Ignoring failure'</span>);
      }

    };

    <span class="comment">/**
     * flash 9/movieStar + RTMP-only method for unhandled warnings/exceptions from Flash
     * e.g., RTMP "method missing" warning (non-fatal) for getStreamLength on server
     */</span>

    <span class="keyword">this</span>._onwarning = <span class="keyword">function</span>(msg, level, code) {

      <span class="keyword">if</span> (s._iO.onwarning) {
        s._iO.onwarning(msg, level, code);
      }

    };

    <span class="keyword">this</span>._onfinish = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-230">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-230">&#182;</a>
              </div>
              <p>store local copy before it gets trashed...</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">var</span> io_onfinish = s._iO.onfinish;

      s._onbufferchange(<span class="number">0</span>);
      s._resetOnPosition(<span class="number">0</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-231">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-231">&#182;</a>
              </div>
              <p>reset some state items</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (s.instanceCount) {

        s.instanceCount--;

        <span class="keyword">if</span> (!s.instanceCount) {</pre></div></div>
            
        </li>
        
        
        <li id="section-232">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-232">&#182;</a>
              </div>
              <p>remove onPosition listeners, if any</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          detachOnPosition();</pre></div></div>
            
        </li>
        
        
        <li id="section-233">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-233">&#182;</a>
              </div>
              <p>reset instance options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s.playState = <span class="number">0</span>;
          s.paused = <span class="literal">false</span>;
          s.instanceCount = <span class="number">0</span>;
          s.instanceOptions = {};
          s._iO = {};
          stop_html5_timer();</pre></div></div>
            
        </li>
        
        
        <li id="section-234">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-234">&#182;</a>
              </div>
              <p>reset position, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (s.isHTML5) {
            s.position = <span class="number">0</span>;
          }

        }

        <span class="keyword">if</span> (!s.instanceCount || s._iO.multiShotEvents) {</pre></div></div>
            
        </li>
        
        
        <li id="section-235">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-235">&#182;</a>
              </div>
              <p>fire onfinish for last, or every instance</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (io_onfinish) {
            sm2._wD(s.id + <span class="string">': onfinish()'</span>);
            wrapCallback(s, <span class="keyword">function</span>() {
              io_onfinish.apply(s);
            });
          }
        }

      }

    };

    <span class="keyword">this</span>._whileloading = <span class="keyword">function</span>(nBytesLoaded, nBytesTotal, nDuration, nBufferLength) {

      <span class="keyword">var</span> instanceOptions = s._iO;

      s.bytesLoaded = nBytesLoaded;
      s.bytesTotal = nBytesTotal;
      s.duration = Math.floor(nDuration);
      s.bufferLength = nBufferLength;

      <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; !instanceOptions.isMovieStar) {

        <span class="keyword">if</span> (instanceOptions.duration) {</pre></div></div>
            
        </li>
        
        
        <li id="section-236">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-236">&#182;</a>
              </div>
              <p>use duration from options, if specified and larger. nobody should be specifying duration in options, actually, and it should be retired.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          s.durationEstimate = (s.duration &gt; instanceOptions.duration) ? s.duration : instanceOptions.duration;
        } <span class="keyword">else</span> {
          s.durationEstimate = parseInt((s.bytesTotal / s.bytesLoaded) * s.duration, <span class="number">10</span>);
        }

      } <span class="keyword">else</span> {

        s.durationEstimate = s.duration;

      }</pre></div></div>
            
        </li>
        
        
        <li id="section-237">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-237">&#182;</a>
              </div>
              <p>for flash, reflect sequential-load-style buffering</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!s.isHTML5) {
        s.buffered = [{
          start: <span class="number">0</span>,
          end: s.duration
        }];
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-238">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-238">&#182;</a>
              </div>
              <p>allow whileloading to fire even if &quot;load&quot; fired under HTML5, due to HTTP range/partials</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> ((s.readyState !== <span class="number">3</span> || s.isHTML5) &amp;&amp; instanceOptions.whileloading) {
        instanceOptions.whileloading.apply(s);
      }

    };

    <span class="keyword">this</span>._whileplaying = <span class="keyword">function</span>(nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) {

      <span class="keyword">var</span> instanceOptions = s._iO,
          eqLeft;</pre></div></div>
            
        </li>
        
        
        <li id="section-239">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-239">&#182;</a>
              </div>
              <p>flash safety net</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (isNaN(nPosition) || nPosition === <span class="literal">null</span>) <span class="keyword">return</span> <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-240">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-240">&#182;</a>
              </div>
              <p>Safari HTML5 play() may return small -ve values when starting from position: 0, eg. -50.120396875. Unexpected/invalid per W3, I think. Normalize to 0.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s.position = Math.max(<span class="number">0</span>, nPosition);

      s._processOnPosition();

      <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; fV &gt; <span class="number">8</span>) {

        <span class="keyword">if</span> (instanceOptions.usePeakData &amp;&amp; oPeakData !== _<span class="literal">undefined</span> &amp;&amp; oPeakData) {
          s.peakData = {
            left: oPeakData.leftPeak,
            right: oPeakData.rightPeak
          };
        }

        <span class="keyword">if</span> (instanceOptions.useWaveformData &amp;&amp; oWaveformDataLeft !== _<span class="literal">undefined</span> &amp;&amp; oWaveformDataLeft) {
          s.waveformData = {
            left: oWaveformDataLeft.split(<span class="string">','</span>),
            right: oWaveformDataRight.split(<span class="string">','</span>)
          };
        }

        <span class="keyword">if</span> (instanceOptions.useEQData) {
          <span class="keyword">if</span> (oEQData !== _<span class="literal">undefined</span> &amp;&amp; oEQData &amp;&amp; oEQData.leftEQ) {
            eqLeft = oEQData.leftEQ.split(<span class="string">','</span>);
            s.eqData = eqLeft;
            s.eqData.left = eqLeft;
            <span class="keyword">if</span> (oEQData.rightEQ !== _<span class="literal">undefined</span> &amp;&amp; oEQData.rightEQ) {
              s.eqData.right = oEQData.rightEQ.split(<span class="string">','</span>);
            }
          }
        }

      }

      <span class="keyword">if</span> (s.playState === <span class="number">1</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-241">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-241">&#182;</a>
              </div>
              <p>special case/hack: ensure buffering is false if loading from cache (and not yet started)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (!s.isHTML5 &amp;&amp; fV === <span class="number">8</span> &amp;&amp; !s.position &amp;&amp; s.isBuffering) {
          s._onbufferchange(<span class="number">0</span>);
        }

        <span class="keyword">if</span> (instanceOptions.whileplaying) {</pre></div></div>
            
        </li>
        
        
        <li id="section-242">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-242">&#182;</a>
              </div>
              <p>flash may call after actual finish</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          instanceOptions.whileplaying.apply(s);
        }

      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    };

    <span class="keyword">this</span>._oncaptiondata = <span class="keyword">function</span>(oData) {

      <span class="comment">/**
       * internal: flash 9 + NetStream (MovieStar/RTMP-only) feature
       *
       * @param {object} oData
       */</span>

      sm2._wD(s.id + <span class="string">': Caption data received.'</span>);

      s.captiondata = oData;

      <span class="keyword">if</span> (s._iO.oncaptiondata) {
        s._iO.oncaptiondata.apply(s, [oData]);
      }

    };

    <span class="keyword">this</span>._onmetadata = <span class="keyword">function</span>(oMDProps, oMDData) {

      <span class="comment">/**
       * internal: flash 9 + NetStream (MovieStar/RTMP-only) feature
       * RTMP may include song title, MovieStar content may include encoding info
       *
       * @param {array} oMDProps (names)
       * @param {array} oMDData (values)
       */</span>

      sm2._wD(s.id + <span class="string">': Metadata received.'</span>);

      <span class="keyword">var</span> oData = {}, i, j;

      <span class="keyword">for</span> (i = <span class="number">0</span>, j = oMDProps.length; i &lt; j; i++) {
        oData[oMDProps[i]] = oMDData[i];
      }

      s.metadata = oData;

      <span class="keyword">if</span> (s._iO.onmetadata) {
        s._iO.onmetadata.call(s, s.metadata);
      }

    };

    <span class="keyword">this</span>._onid3 = <span class="keyword">function</span>(oID3Props, oID3Data) {

      <span class="comment">/**
       * internal: flash 8 + flash 9 ID3 feature
       * may include artist, song title etc.
       *
       * @param {array} oID3Props (names)
       * @param {array} oID3Data (values)
       */</span>

      sm2._wD(s.id + <span class="string">': ID3 data received.'</span>);

      <span class="keyword">var</span> oData = [], i, j;

      <span class="keyword">for</span> (i = <span class="number">0</span>, j = oID3Props.length; i &lt; j; i++) {
        oData[oID3Props[i]] = oID3Data[i];
      }

      s.id3 = mixin(s.id3, oData);

      <span class="keyword">if</span> (s._iO.onid3) {
        s._iO.onid3.apply(s);
      }

    };</pre></div></div>
            
        </li>
        
        
        <li id="section-243">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-243">&#182;</a>
              </div>
              <p>flash/RTMP-only</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">this</span>._onconnect = <span class="keyword">function</span>(bSuccess) {

      bSuccess = (bSuccess === <span class="number">1</span>);
      sm2._wD(s.id + <span class="string">': '</span> + (bSuccess ? <span class="string">'Connected.'</span> : <span class="string">'Failed to connect? - '</span> + s.url), (bSuccess ? <span class="number">1</span> : <span class="number">2</span>));
      s.connected = bSuccess;

      <span class="keyword">if</span> (bSuccess) {

        s.failures = <span class="number">0</span>;

        <span class="keyword">if</span> (idCheck(s.id)) {
          <span class="keyword">if</span> (s.getAutoPlay()) {</pre></div></div>
            
        </li>
        
        
        <li id="section-244">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-244">&#182;</a>
              </div>
              <p>only update the play state if auto playing</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s.play(_<span class="literal">undefined</span>, s.getAutoPlay());
          } <span class="keyword">else</span> <span class="keyword">if</span> (s._iO.autoLoad) {
            s.load();
          }
        }

        <span class="keyword">if</span> (s._iO.onconnect) {
          s._iO.onconnect.apply(s, [bSuccess]);
        }

      }

    };

    <span class="keyword">this</span>._ondataerror = <span class="keyword">function</span>(sError) {</pre></div></div>
            
        </li>
        
        
        <li id="section-245">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-245">&#182;</a>
              </div>
              <p>flash 9 wave/eq data handler
hack: called at start, and end from flash at/after onfinish()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (s.playState &gt; <span class="number">0</span>) {
        sm2._wD(s.id + <span class="string">': Data error: '</span> + sError);
        <span class="keyword">if</span> (s._iO.ondataerror) {
          s._iO.ondataerror.apply(s);
        }
      }

    };</pre></div></div>
            
        </li>
        
        
        <li id="section-246">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-246">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">this</span>._debug();</pre></div></div>
            
        </li>
        
        
        <li id="section-247">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-247">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  }; <span class="comment">// SMSound()</span>

  <span class="comment">/**
   * Private SoundManager internals
   * ------------------------------
   */</span>

  getDocument = <span class="keyword">function</span>() {

    <span class="keyword">return</span> (doc.body || doc.getElementsByTagName(<span class="string">'div'</span>)[<span class="number">0</span>]);

  };

  id = <span class="keyword">function</span>(sID) {

    <span class="keyword">return</span> doc.getElementById(sID);

  };

  mixin = <span class="keyword">function</span>(oMain, oAdd) {</pre></div></div>
            
        </li>
        
        
        <li id="section-248">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-248">&#182;</a>
              </div>
              <p>non-destructive merge</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> o1 = (oMain || {}), o2, o;</pre></div></div>
            
        </li>
        
        
        <li id="section-249">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-249">&#182;</a>
              </div>
              <p>if unspecified, o2 is the default options object</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    o2 = (oAdd === _<span class="literal">undefined</span> ? sm2.defaultOptions : oAdd);

    <span class="keyword">for</span> (o <span class="keyword">in</span> o2) {

      <span class="keyword">if</span> (o2.hasOwnProperty(o) &amp;&amp; o1[o] === _<span class="literal">undefined</span>) {

        <span class="keyword">if</span> (<span class="keyword">typeof</span> o2[o] !== <span class="string">'object'</span> || o2[o] === <span class="literal">null</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-250">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-250">&#182;</a>
              </div>
              <p>assign directly</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          o1[o] = o2[o];

        } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-251">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-251">&#182;</a>
              </div>
              <p>recurse through o2</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          o1[o] = mixin(o1[o], o2[o]);

        }

      }

    }

    <span class="keyword">return</span> o1;

  };

  wrapCallback = <span class="keyword">function</span>(oSound, callback) {

    <span class="comment">/**
     * 03/03/2013: Fix for Flash Player 11.6.602.171 + Flash 8 (flashVersion = 8) SWF issue
     * setTimeout() fix for certain SMSound callbacks like onload() and onfinish(), where subsequent calls like play() and load() fail when Flash Player 11.6.602.171 is installed, and using soundManager with flashVersion = 8 (which is the default).
     * Not sure of exact cause. Suspect race condition and/or invalid (NaN-style) position argument trickling down to the next JS -&gt; Flash _start() call, in the play() case.
     * Fix: setTimeout() to yield, plus safer null / NaN checking on position argument provided to Flash.
     * https://getsatisfaction.com/schillmania/topics/recent_chrome_update_seems_to_have_broken_my_sm2_audio_player
     */</span>
    <span class="keyword">if</span> (!oSound.isHTML5 &amp;&amp; fV === <span class="number">8</span>) {
      window.setTimeout(callback, <span class="number">0</span>);
    } <span class="keyword">else</span> {
      callback();
    }

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-252">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-252">&#182;</a>
              </div>
              <p>additional soundManager properties that soundManager.setup() will accept</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  extraOptions = {
    onready: <span class="number">1</span>,
    ontimeout: <span class="number">1</span>,
    defaultOptions: <span class="number">1</span>,
    flash9Options: <span class="number">1</span>,
    movieStarOptions: <span class="number">1</span>
  };

  assign = <span class="keyword">function</span>(o, oParent) {

    <span class="comment">/**
     * recursive assignment of properties, soundManager.setup() helper
     * allows property assignment based on whitelist
     */</span>

    <span class="keyword">var</span> i,
        result = <span class="literal">true</span>,
        hasParent = (oParent !== _<span class="literal">undefined</span>),
        setupOptions = sm2.setupOptions,
        bonusOptions = extraOptions;</pre></div></div>
            
        </li>
        
        
        <li id="section-253">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-253">&#182;</a>
              </div>
              <d>

            </div>
            
        </li>
        
        
        <li id="section-254">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-254">&#182;</a>
              </div>
              <p>if soundManager.setup() called, show accepted parameters.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (o === _<span class="literal">undefined</span>) {

      result = [];

      <span class="keyword">for</span> (i <span class="keyword">in</span> setupOptions) {

        <span class="keyword">if</span> (setupOptions.hasOwnProperty(i)) {
          result.push(i);
        }

      }

      <span class="keyword">for</span> (i <span class="keyword">in</span> bonusOptions) {

        <span class="keyword">if</span> (bonusOptions.hasOwnProperty(i)) {

          <span class="keyword">if</span> (<span class="keyword">typeof</span> sm2[i] === <span class="string">'object'</span>) {
            result.push(i + <span class="string">': {...}'</span>);
          } <span class="keyword">else</span> <span class="keyword">if</span> (sm2[i] <span class="keyword">instanceof</span> Function) {
            result.push(i + <span class="string">': function() {...}'</span>);
          } <span class="keyword">else</span> {
            result.push(i);
          }

        }

      }

      sm2._wD(str(<span class="string">'setup'</span>, result.join(<span class="string">', '</span>)));

      <span class="keyword">return</span> <span class="literal">false</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-255">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-255">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">for</span> (i <span class="keyword">in</span> o) {

      <span class="keyword">if</span> (o.hasOwnProperty(i)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-256">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-256">&#182;</a>
              </div>
              <p>if not an {object} we want to recurse through...</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        <span class="keyword">if</span> (<span class="keyword">typeof</span> o[i] !== <span class="string">'object'</span> || o[i] === <span class="literal">null</span> || o[i] <span class="keyword">instanceof</span> Array || o[i] <span class="keyword">instanceof</span> RegExp) {</pre></div></div>
            
        </li>
        
        
        <li id="section-257">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-257">&#182;</a>
              </div>
              <p>check &quot;allowed&quot; options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          <span class="keyword">if</span> (hasParent &amp;&amp; bonusOptions[oParent] !== _<span class="literal">undefined</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-258">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-258">&#182;</a>
              </div>
              <p>valid recursive / nested object option, eg., { defaultOptions: { volume: 50 } }</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2[oParent][i] = o[i];

          } <span class="keyword">else</span> <span class="keyword">if</span> (setupOptions[i] !== _<span class="literal">undefined</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-259">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-259">&#182;</a>
              </div>
              <p>special case: assign to setupOptions object, which soundManager property references</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2.setupOptions[i] = o[i];</pre></div></div>
            
        </li>
        
        
        <li id="section-260">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-260">&#182;</a>
              </div>
              <p>assign directly to soundManager, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2[i] = o[i];

          } <span class="keyword">else</span> <span class="keyword">if</span> (bonusOptions[i] === _<span class="literal">undefined</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-261">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-261">&#182;</a>
              </div>
              <p>invalid or disallowed parameter. complain.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            complain(str((sm2[i] === _<span class="literal">undefined</span> ? <span class="string">'setupUndef'</span> : <span class="string">'setupError'</span>), i), <span class="number">2</span>);

            result = <span class="literal">false</span>;

          } <span class="keyword">else</span> <span class="keyword">if</span> (sm2[i] <span class="keyword">instanceof</span> Function) {

            <span class="comment">/**
             * valid extraOptions (bonusOptions) parameter.
             * is it a method, like onready/ontimeout? call it.
             * multiple parameters should be in an array, eg. soundManager.setup({onready: [myHandler, myScope]});
             */</span>
            sm2[i].apply(sm2, (o[i] <span class="keyword">instanceof</span> Array ? o[i] : [o[i]]));

          } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-262">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-262">&#182;</a>
              </div>
              <p>good old-fashioned direct assignment</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2[i] = o[i];

          }

        } <span class="keyword">else</span> <span class="keyword">if</span> (bonusOptions[i] === _<span class="literal">undefined</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-263">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-263">&#182;</a>
              </div>
              <p>recursion case, eg., { defaultOptions: { ... } }</p>

            </div>
            
        </li>
        
        
        <li id="section-264">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-264">&#182;</a>
              </div>
              <p>invalid or disallowed parameter. complain.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          complain(str((sm2[i] === _<span class="literal">undefined</span> ? <span class="string">'setupUndef'</span> : <span class="string">'setupError'</span>), i), <span class="number">2</span>);

          result = <span class="literal">false</span>;

        } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-265">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-265">&#182;</a>
              </div>
              <p>recurse through object</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">return</span> assign(o[i], i);

        }

      }

    }

    <span class="keyword">return</span> result;

  };

  <span class="function"><span class="keyword">function</span> <span class="title">preferFlashCheck</span><span class="params">(kind)</span> {</span></pre></div></div>
            
        </li>
        
        
        <li id="section-266">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-266">&#182;</a>
              </div>
              <p>whether flash should play a given type</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">return</span> (sm2.preferFlash &amp;&amp; hasFlash &amp;&amp; !sm2.ignoreFlash &amp;&amp; (sm2.flash[kind] !== _<span class="literal">undefined</span> &amp;&amp; sm2.flash[kind]));

  }

  <span class="comment">/**
   * Internal DOM2-level event helpers
   * ---------------------------------
   */</span>

  event = (<span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-267">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-267">&#182;</a>
              </div>
              <p>normalize event methods</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> old = (window.attachEvent),
    evt = {
      add: (old ? <span class="string">'attachEvent'</span> : <span class="string">'addEventListener'</span>),
      remove: (old ? <span class="string">'detachEvent'</span> : <span class="string">'removeEventListener'</span>)
    };</pre></div></div>
            
        </li>
        
        
        <li id="section-268">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-268">&#182;</a>
              </div>
              <p>normalize &quot;on&quot; event prefix, optional capture argument</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="function"><span class="keyword">function</span> <span class="title">getArgs</span><span class="params">(oArgs)</span> {</span>

      <span class="keyword">var</span> args = slice.call(oArgs),
          len = args.length;

      <span class="keyword">if</span> (old) {</pre></div></div>
            
        </li>
        
        
        <li id="section-269">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-269">&#182;</a>
              </div>
              <p>prefix</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        args[<span class="number">1</span>] = <span class="string">'on'</span> + args[<span class="number">1</span>];
        <span class="keyword">if</span> (len &gt; <span class="number">3</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-270">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-270">&#182;</a>
              </div>
              <p>no capture</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          args.pop();
        }
      } <span class="keyword">else</span> <span class="keyword">if</span> (len === <span class="number">3</span>) {
        args.push(<span class="literal">false</span>);
      }

      <span class="keyword">return</span> args;

    }

    <span class="function"><span class="keyword">function</span> <span class="title">apply</span><span class="params">(args, sType)</span> {</span></pre></div></div>
            
        </li>
        
        
        <li id="section-271">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-271">&#182;</a>
              </div>
              <p>normalize and call the event method, with the proper arguments</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">var</span> element = args.shift(),
          method = [evt[sType]];

      <span class="keyword">if</span> (old) {</pre></div></div>
            
        </li>
        
        
        <li id="section-272">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-272">&#182;</a>
              </div>
              <p>old IE can&#39;t do apply().</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        element[method](args[<span class="number">0</span>], args[<span class="number">1</span>]);
      } <span class="keyword">else</span> {
        element[method].apply(element, args);
      }

    }

    <span class="function"><span class="keyword">function</span> <span class="title">add</span><span class="params">()</span> {</span>
      apply(getArgs(arguments), <span class="string">'add'</span>);
    }

    <span class="function"><span class="keyword">function</span> <span class="title">remove</span><span class="params">()</span> {</span>
      apply(getArgs(arguments), <span class="string">'remove'</span>);
    }

    <span class="keyword">return</span> {
      add: add,
      remove: remove
    };

  }());

  <span class="comment">/**
   * Internal HTML5 event handling
   * -----------------------------
   */</span>

  <span class="function"><span class="keyword">function</span> <span class="title">html5_event</span><span class="params">(oFn)</span> {</span></pre></div></div>
            
        </li>
        
        
        <li id="section-273">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-273">&#182;</a>
              </div>
              <p>wrap html5 event handlers so we don&#39;t call them on destroyed and/or unloaded sounds</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">return</span> <span class="keyword">function</span>(e) {

      <span class="keyword">var</span> s = <span class="keyword">this</span>._s,
          result;

      <span class="keyword">if</span> (!s || !s._a) {</pre></div></div>
            
        </li>
        
        
        <li id="section-274">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-274">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (s &amp;&amp; s.id) {
          sm2._wD(s.id + <span class="string">': Ignoring '</span> + e.type);
        } <span class="keyword">else</span> {
          sm2._wD(h5 + <span class="string">'Ignoring '</span> + e.type);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-275">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-275">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        result = <span class="literal">null</span>;
      } <span class="keyword">else</span> {
        result = oFn.call(<span class="keyword">this</span>, e);
      }

      <span class="keyword">return</span> result;

    };

  }

  html5_events = {</pre></div></div>
            
        </li>
        
        
        <li id="section-276">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-276">&#182;</a>
              </div>
              <p>HTML5 event-name-to-handler map</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    abort: html5_event(<span class="keyword">function</span>() {

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': abort'</span>);

    }),</pre></div></div>
            
        </li>
        
        
        <li id="section-277">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-277">&#182;</a>
              </div>
              <p>enough has loaded to play</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    canplay: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">var</span> s = <span class="keyword">this</span>._s,
          position1K;

      <span class="keyword">if</span> (s._html5_canplay) {</pre></div></div>
            
        </li>
        
        
        <li id="section-278">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-278">&#182;</a>
              </div>
              <p>this event has already fired. ignore.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">return</span>;
      }

      s._html5_canplay = <span class="literal">true</span>;
      sm2._wD(s.id + <span class="string">': canplay'</span>);
      s._onbufferchange(<span class="number">0</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-279">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-279">&#182;</a>
              </div>
              <p>position according to instance options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      position1K = (s._iO.position !== _<span class="literal">undefined</span> &amp;&amp; !isNaN(s._iO.position) ? s._iO.position / msecScale : <span class="literal">null</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-280">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-280">&#182;</a>
              </div>
              <p>set the position if position was provided before the sound loaded</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (<span class="keyword">this</span>.currentTime !== position1K) {
        sm2._wD(s.id + <span class="string">': canplay: Setting position to '</span> + position1K);
        <span class="keyword">try</span> {
          <span class="keyword">this</span>.currentTime = position1K;
        } <span class="keyword">catch</span>(ee) {
          sm2._wD(s.id + <span class="string">': canplay: Setting position of '</span> + position1K + <span class="string">' failed: '</span> + ee.message, <span class="number">2</span>);
        }
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-281">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-281">&#182;</a>
              </div>
              <p>hack for HTML5 from/to case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (s._iO._oncanplay) {
        s._iO._oncanplay();
      }

    }),

    canplaythrough: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">var</span> s = <span class="keyword">this</span>._s;

      <span class="keyword">if</span> (!s.loaded) {
        s._onbufferchange(<span class="number">0</span>);
        s._whileloading(s.bytesLoaded, s.bytesTotal, s._get_html5_duration());
        s._onload(<span class="literal">true</span>);
      }

    }),

    durationchange: html5_event(<span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-282">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-282">&#182;</a>
              </div>
              <p>durationchange may fire at various times, probably the safest way to capture accurate/final duration.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">var</span> s = <span class="keyword">this</span>._s,
          duration;

      duration = s._get_html5_duration();

      <span class="keyword">if</span> (!isNaN(duration) &amp;&amp; duration !== s.duration) {

        sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': durationchange ('</span> + duration + <span class="string">')'</span> + (s.duration ? <span class="string">', previously '</span> + s.duration : <span class="string">''</span>));

        s.durationEstimate = s.duration = duration;

      }

    }),</pre></div></div>
            
        </li>
        
        
        <li id="section-283">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-283">&#182;</a>
              </div>
              <p>TODO: Reserved for potential use</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="comment">/*
    emptied: html5_event(function() {

      sm2._wD(this._s.id + ': emptied');

    }),
    */</span>

    ended: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">var</span> s = <span class="keyword">this</span>._s;

      sm2._wD(s.id + <span class="string">': ended'</span>);

      s._onfinish();

    }),

    error: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">var</span> description = (html5ErrorCodes[<span class="keyword">this</span>.error.code] || <span class="literal">null</span>);
      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': HTML5 error, code '</span> + <span class="keyword">this</span>.error.code + (description ? <span class="string">' ('</span> + description + <span class="string">')'</span> : <span class="string">''</span>));
      <span class="keyword">this</span>._s._onload(<span class="literal">false</span>);
      <span class="keyword">this</span>._s._onerror(<span class="keyword">this</span>.error.code, description);

    }),

    loadeddata: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">var</span> s = <span class="keyword">this</span>._s;

      sm2._wD(s.id + <span class="string">': loadeddata'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-284">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-284">&#182;</a>
              </div>
              <p>safari seems to nicely report progress events, eventually totalling 100%</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!s._loaded &amp;&amp; !isSafari) {
        s.duration = s._get_html5_duration();
      }

    }),

    loadedmetadata: html5_event(<span class="keyword">function</span>() {

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': loadedmetadata'</span>);

    }),

    loadstart: html5_event(<span class="keyword">function</span>() {

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': loadstart'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-285">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-285">&#182;</a>
              </div>
              <p>assume buffering at first</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">this</span>._s._onbufferchange(<span class="number">1</span>);

    }),

    play: html5_event(<span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-286">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-286">&#182;</a>
              </div>
              <p>sm2._wD(this._s.id + &#39;: play()&#39;);
once play starts, no buffering</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">this</span>._s._onbufferchange(<span class="number">0</span>);

    }),

    playing: html5_event(<span class="keyword">function</span>() {

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': playing '</span> + String.fromCharCode(<span class="number">9835</span>));</pre></div></div>
            
        </li>
        
        
        <li id="section-287">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-287">&#182;</a>
              </div>
              <p>once play starts, no buffering</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">this</span>._s._onbufferchange(<span class="number">0</span>);

    }),

    progress: html5_event(<span class="keyword">function</span>(e) {</pre></div></div>
            
        </li>
        
        
        <li id="section-288">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-288">&#182;</a>
              </div>
              <p>note: can fire repeatedly after &quot;loaded&quot; event, due to use of HTTP range/partials</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">var</span> s = <span class="keyword">this</span>._s,
          i, j, progStr, buffered = <span class="number">0</span>,
          isProgress = (e.type === <span class="string">'progress'</span>),
          ranges = e.target.buffered,</pre></div></div>
            
        </li>
        
        
        <li id="section-289">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-289">&#182;</a>
              </div>
              <p>firefox 3.6 implements e.loaded/total (bytes)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          loaded = (e.loaded || <span class="number">0</span>),
          total = (e.total || <span class="number">1</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-290">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-290">&#182;</a>
              </div>
              <p>reset the &quot;buffered&quot; (loaded byte ranges) array</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s.buffered = [];

      <span class="keyword">if</span> (ranges &amp;&amp; ranges.length) {</pre></div></div>
            
        </li>
        
        
        <li id="section-291">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-291">&#182;</a>
              </div>
              <p>if loaded is 0, try TimeRanges implementation as % of load
<a href="https://developer.mozilla.org/en/DOM/TimeRanges">https://developer.mozilla.org/en/DOM/TimeRanges</a></p>

            </div>
            
        </li>
        
        
        <li id="section-292">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-292">&#182;</a>
              </div>
              <p>re-build &quot;buffered&quot; array
HTML5 returns seconds. SM2 API uses msec for setPosition() etc., whether Flash or HTML5.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">for</span> (i = <span class="number">0</span>, j = ranges.length; i &lt; j; i++) {
          s.buffered.push({
            start: ranges.start(i) * msecScale,
            end: ranges.end(i) * msecScale
          });
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-293">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-293">&#182;</a>
              </div>
              <p>use the last value locally</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        buffered = (ranges.end(<span class="number">0</span>) - ranges.start(<span class="number">0</span>)) * msecScale;</pre></div></div>
            
        </li>
        
        
        <li id="section-294">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-294">&#182;</a>
              </div>
              <p>linear case, buffer sum; does not account for seeking and HTTP partials / byte ranges</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        loaded = Math.min(<span class="number">1</span>, buffered / (e.target.duration * msecScale));</pre></div></div>
            
        </li>
        
        
        <li id="section-295">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-295">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (isProgress &amp;&amp; ranges.length &gt; <span class="number">1</span>) {
          progStr = [];
          j = ranges.length;
          <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; j; i++) {
            progStr.push((e.target.buffered.start(i) * msecScale) + <span class="string">'-'</span> + (e.target.buffered.end(i) * msecScale));
          }
          sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': progress, timeRanges: '</span> + progStr.join(<span class="string">', '</span>));
        }

        <span class="keyword">if</span> (isProgress &amp;&amp; !isNaN(loaded)) {
          sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': progress, '</span> + Math.floor(loaded * <span class="number">100</span>) + <span class="string">'% loaded'</span>);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-296">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-296">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      }

      <span class="keyword">if</span> (!isNaN(loaded)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-297">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-297">&#182;</a>
              </div>
              <p>TODO: prevent calls with duplicate values.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        s._whileloading(loaded, total, s._get_html5_duration());
        <span class="keyword">if</span> (loaded &amp;&amp; total &amp;&amp; loaded === total) {</pre></div></div>
            
        </li>
        
        
        <li id="section-298">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-298">&#182;</a>
              </div>
              <p>in case &quot;onload&quot; doesn&#39;t fire (eg. gecko 1.9.2)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          html5_events.canplaythrough.call(<span class="keyword">this</span>, e);
        }

      }

    }),

    ratechange: html5_event(<span class="keyword">function</span>() {

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': ratechange'</span>);

    }),

    suspend: html5_event(<span class="keyword">function</span>(e) {</pre></div></div>
            
        </li>
        
        
        <li id="section-299">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-299">&#182;</a>
              </div>
              <p>download paused/stopped, may have finished (eg. onload)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">var</span> s = <span class="keyword">this</span>._s;

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': suspend'</span>);
      html5_events.progress.call(<span class="keyword">this</span>, e);
      s._onsuspend();

    }),

    stalled: html5_event(<span class="keyword">function</span>() {

      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': stalled'</span>);

    }),

    timeupdate: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">this</span>._s._onTimer();

    }),

    waiting: html5_event(<span class="keyword">function</span>() {

      <span class="keyword">var</span> s = <span class="keyword">this</span>._s;</pre></div></div>
            
        </li>
        
        
        <li id="section-300">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-300">&#182;</a>
              </div>
              <p>see also: seeking</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2._wD(<span class="keyword">this</span>._s.id + <span class="string">': waiting'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-301">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-301">&#182;</a>
              </div>
              <p>playback faster than download rate, etc.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      s._onbufferchange(<span class="number">1</span>);

    })

  };

  html5OK = <span class="keyword">function</span>(iO) {</pre></div></div>
            
        </li>
        
        
        <li id="section-302">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-302">&#182;</a>
              </div>
              <p>playability test based on URL or MIME type</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> result;

    <span class="keyword">if</span> (!iO || (!iO.type &amp;&amp; !iO.url &amp;&amp; !iO.serverURL)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-303">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-303">&#182;</a>
              </div>
              <p>nothing to check</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = <span class="literal">false</span>;

    } <span class="keyword">else</span> <span class="keyword">if</span> (iO.serverURL || (iO.type &amp;&amp; preferFlashCheck(iO.type))) {</pre></div></div>
            
        </li>
        
        
        <li id="section-304">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-304">&#182;</a>
              </div>
              <p>RTMP, or preferring flash</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = <span class="literal">false</span>;

    } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-305">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-305">&#182;</a>
              </div>
              <p>Use type, if specified. Pass data: URIs to HTML5. If HTML5-only mode, no other options, so just give &#39;er</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = ((iO.type ? html5CanPlay({ type: iO.type }) : html5CanPlay({ url: iO.url }) || sm2.html5Only || iO.url.match(<span class="regexp">/data:/i</span>)));

    }

    <span class="keyword">return</span> result;

  };

  html5Unload = <span class="keyword">function</span>(oAudio) {

    <span class="comment">/**
     * Internal method: Unload media, and cancel any current/pending network requests.
     * Firefox can load an empty URL, which allegedly destroys the decoder and stops the download.
     * https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Stopping_the_download_of_media
     * However, Firefox has been seen loading a relative URL from '' and thus requesting the hosting page on unload.
     * Other UA behaviour is unclear, so everyone else gets an about:blank-style URL.
     */</span>

    <span class="keyword">var</span> url;

    <span class="keyword">if</span> (oAudio) {</pre></div></div>
            
        </li>
        
        
        <li id="section-306">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-306">&#182;</a>
              </div>
              <p>Firefox and Chrome accept short WAVe data: URIs. Chome dislikes audio/wav, but accepts audio/wav for data: MIME.
Desktop Safari complains / fails on data: URI, so it gets about:blank.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      url = (isSafari ? emptyURL : (sm2.html5.canPlayType(<span class="string">'audio/wav'</span>) ? emptyWAV : emptyURL));

      oAudio.src = url;</pre></div></div>
            
        </li>
        
        
        <li id="section-307">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-307">&#182;</a>
              </div>
              <p>reset some state, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (oAudio._called_unload !== _<span class="literal">undefined</span>) {
        oAudio._called_load = <span class="literal">false</span>;
      }

    }

    <span class="keyword">if</span> (useGlobalHTML5Audio) {</pre></div></div>
            
        </li>
        
        
        <li id="section-308">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-308">&#182;</a>
              </div>
              <p>ensure URL state is trashed, also</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      lastGlobalHTML5URL = <span class="literal">null</span>;

    }

    <span class="keyword">return</span> url;

  };

  html5CanPlay = <span class="keyword">function</span>(o) {

    <span class="comment">/**
     * Try to find MIME, test and return truthiness
     * o = {
     *  url: '/path/to/an.mp3',
     *  type: 'audio/mp3'
     * }
     */</span>

    <span class="keyword">if</span> (!sm2.useHTML5Audio || !sm2.hasHTML5) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">var</span> url = (o.url || <span class="literal">null</span>),
        mime = (o.type || <span class="literal">null</span>),
        aF = sm2.audioFormats,
        result,
        offset,
        fileExt,
        item;</pre></div></div>
            
        </li>
        
        
        <li id="section-309">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-309">&#182;</a>
              </div>
              <p>account for known cases like audio/mp3</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (mime &amp;&amp; sm2.html5[mime] !== _<span class="literal">undefined</span>) <span class="keyword">return</span> (sm2.html5[mime] &amp;&amp; !preferFlashCheck(mime));

    <span class="keyword">if</span> (!html5Ext) {

      html5Ext = [];

      <span class="keyword">for</span> (item <span class="keyword">in</span> aF) {

        <span class="keyword">if</span> (aF.hasOwnProperty(item)) {

          html5Ext.push(item);

          <span class="keyword">if</span> (aF[item].related) {
            html5Ext = html5Ext.concat(aF[item].related);
          }

        }

      }

      html5Ext = <span class="keyword">new</span> RegExp(<span class="string">'\\.('</span> + html5Ext.join(<span class="string">'|'</span>) + <span class="string">')(\\?.*)?$'</span>, <span class="string">'i'</span>);

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-310">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-310">&#182;</a>
              </div>
              <p>TODO: Strip URL queries, etc.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    fileExt = (url ? url.toLowerCase().match(html5Ext) : <span class="literal">null</span>);

    <span class="keyword">if</span> (!fileExt || !fileExt.length) {

      <span class="keyword">if</span> (!mime) {

        result = <span class="literal">false</span>;

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-311">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-311">&#182;</a>
              </div>
              <p>audio/mp3 -&gt; mp3, result should be known</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        offset = mime.indexOf(<span class="string">';'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-312">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-312">&#182;</a>
              </div>
              <p>strip &quot;audio/X; codecs...&quot;</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        fileExt = (offset !== -<span class="number">1</span> ? mime.substr(<span class="number">0</span>, offset) : mime).substr(<span class="number">6</span>);

      }

    } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-313">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-313">&#182;</a>
              </div>
              <p>match the raw extension name - &quot;mp3&quot;, for example</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      fileExt = fileExt[<span class="number">1</span>];

    }

    <span class="keyword">if</span> (fileExt &amp;&amp; sm2.html5[fileExt] !== _<span class="literal">undefined</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-314">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-314">&#182;</a>
              </div>
              <p>result known</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = (sm2.html5[fileExt] &amp;&amp; !preferFlashCheck(fileExt));

    } <span class="keyword">else</span> {

      mime = <span class="string">'audio/'</span> + fileExt;
      result = sm2.html5.canPlayType({ type: mime });

      sm2.html5[fileExt] = result;</pre></div></div>
            
        </li>
        
        
        <li id="section-315">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-315">&#182;</a>
              </div>
              <p>sm2._wD(&#39;canPlayType, found result: &#39; + result);</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = (result &amp;&amp; sm2.html5[mime] &amp;&amp; !preferFlashCheck(mime));
    }

    <span class="keyword">return</span> result;

  };

  testHTML5 = <span class="keyword">function</span>() {

    <span class="comment">/**
     * Internal: Iterates over audioFormats, determining support eg. audio/mp3, audio/mpeg and so on
     * assigns results to html5[] and flash[].
     */</span>

    <span class="keyword">if</span> (!sm2.useHTML5Audio || !sm2.hasHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-316">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-316">&#182;</a>
              </div>
              <p>without HTML5, we need Flash.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.html5.usingFlash = <span class="literal">true</span>;
      needsFlash = <span class="literal">true</span>;

      <span class="keyword">return</span> <span class="literal">false</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-317">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-317">&#182;</a>
              </div>
              <p>double-whammy: Opera 9.64 throws WRONG_ARGUMENTS_ERR if no parameter passed to Audio(), and Webkit + iOS happily tries to load &quot;null&quot; as a URL. :/</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> a = (Audio !== _<span class="literal">undefined</span> ? (isOpera &amp;&amp; opera.version() &lt; <span class="number">10</span> ? <span class="keyword">new</span> Audio(<span class="literal">null</span>) : <span class="keyword">new</span> Audio()) : <span class="literal">null</span>),
        item, lookup, support = {}, aF, i;

    <span class="function"><span class="keyword">function</span> <span class="title">cp</span><span class="params">(m)</span> {</span>

      <span class="keyword">var</span> canPlay, j,
          result = <span class="literal">false</span>,
          isOK = <span class="literal">false</span>;

      <span class="keyword">if</span> (!a || <span class="keyword">typeof</span> a.canPlayType !== <span class="string">'function'</span>) <span class="keyword">return</span> result;

      <span class="keyword">if</span> (m <span class="keyword">instanceof</span> Array) {</pre></div></div>
            
        </li>
        
        
        <li id="section-318">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-318">&#182;</a>
              </div>
              <p>iterate through all mime types, return any successes</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        <span class="keyword">for</span> (i = <span class="number">0</span>, j = m.length; i &lt; j; i++) {

          <span class="keyword">if</span> (sm2.html5[m[i]] || a.canPlayType(m[i]).match(sm2.html5Test)) {

            isOK = <span class="literal">true</span>;
            sm2.html5[m[i]] = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-319">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-319">&#182;</a>
              </div>
              <p>note flash support, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            sm2.flash[m[i]] = !!(m[i].match(flashMIME));

          }

        }

        result = isOK;

      } <span class="keyword">else</span> {

        canPlay = (a &amp;&amp; <span class="keyword">typeof</span> a.canPlayType === <span class="string">'function'</span> ? a.canPlayType(m) : <span class="literal">false</span>);
        result = !!(canPlay &amp;&amp; (canPlay.match(sm2.html5Test)));

      }

      <span class="keyword">return</span> result;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-320">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-320">&#182;</a>
              </div>
              <p>test all registered formats + codecs</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    aF = sm2.audioFormats;

    <span class="keyword">for</span> (item <span class="keyword">in</span> aF) {

      <span class="keyword">if</span> (aF.hasOwnProperty(item)) {

        lookup = <span class="string">'audio/'</span> + item;

        support[item] = cp(aF[item].type);</pre></div></div>
            
        </li>
        
        
        <li id="section-321">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-321">&#182;</a>
              </div>
              <p>write back generic type too, eg. audio/mp3</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        support[lookup] = support[item];</pre></div></div>
            
        </li>
        
        
        <li id="section-322">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-322">&#182;</a>
              </div>
              <p>assign flash</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (item.match(flashMIME)) {

          sm2.flash[item] = <span class="literal">true</span>;
          sm2.flash[lookup] = <span class="literal">true</span>;

        } <span class="keyword">else</span> {

          sm2.flash[item] = <span class="literal">false</span>;
          sm2.flash[lookup] = <span class="literal">false</span>;

        }</pre></div></div>
            
        </li>
        
        
        <li id="section-323">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-323">&#182;</a>
              </div>
              <p>assign result to related formats, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        <span class="keyword">if</span> (aF[item] &amp;&amp; aF[item].related) {

          <span class="keyword">for</span> (i = aF[item].related.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {</pre></div></div>
            
        </li>
        
        
        <li id="section-324">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-324">&#182;</a>
              </div>
              <p>eg. audio/m4a</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            support[<span class="string">'audio/'</span> + aF[item].related[i]] = support[item];
            sm2.html5[aF[item].related[i]] = support[item];
            sm2.flash[aF[item].related[i]] = support[item];

          }

        }

      }

    }

    support.canPlayType = (a ? cp : <span class="literal">null</span>);
    sm2.html5 = mixin(sm2.html5, support);

    sm2.html5.usingFlash = featureCheck();
    needsFlash = sm2.html5.usingFlash;

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  strings = {</pre></div></div>
            
        </li>
        
        
        <li id="section-325">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-325">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    notReady: <span class="string">'Unavailable - wait until onready() has fired.'</span>,
    notOK: <span class="string">'Audio support is not available.'</span>,
    domError: sm + <span class="string">'exception caught while appending SWF to DOM.'</span>,
    spcWmode: <span class="string">'Removing wmode, preventing known SWF loading issue(s)'</span>,
    swf404: smc + <span class="string">'Verify that %s is a valid path.'</span>,
    tryDebug: <span class="string">'Try '</span> + sm + <span class="string">'.debugFlash = true for more security details (output goes to SWF.)'</span>,
    checkSWF: <span class="string">'See SWF output for more debug info.'</span>,
    localFail: smc + <span class="string">'Non-HTTP page ('</span> + doc.location.protocol + <span class="string">' URL?) Review Flash player security settings for this special case:\nhttp://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html\nMay need to add/allow path, eg. c:/sm2/ or /users/me/sm2/'</span>,
    waitFocus: smc + <span class="string">'Special case: Waiting for SWF to load with window focus...'</span>,
    waitForever: smc + <span class="string">'Waiting indefinitely for Flash (will recover if unblocked)...'</span>,
    waitSWF: smc + <span class="string">'Waiting for 100% SWF load...'</span>,
    needFunction: smc + <span class="string">'Function object expected for %s'</span>,
    badID: <span class="string">'Sound ID "%s" should be a string, starting with a non-numeric character'</span>,
    currentObj: smc + <span class="string">'_debug(): Current sound objects'</span>,
    waitOnload: smc + <span class="string">'Waiting for window.onload()'</span>,
    docLoaded: smc + <span class="string">'Document already loaded'</span>,
    onload: smc + <span class="string">'initComplete(): calling soundManager.onload()'</span>,
    onloadOK: sm + <span class="string">'.onload() complete'</span>,
    didInit: smc + <span class="string">'init(): Already called?'</span>,
    secNote: <span class="string">'Flash security note: Network/internet URLs will not load due to security restrictions. Access can be configured via Flash Player Global Security Settings Page: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html'</span>,
    badRemove: smc + <span class="string">'Failed to remove Flash node.'</span>,
    shutdown: sm + <span class="string">'.disable(): Shutting down'</span>,
    queue: smc + <span class="string">'Queueing %s handler'</span>,
    smError: <span class="string">'SMSound.load(): Exception: JS-Flash communication failed, or JS error.'</span>,
    fbTimeout: <span class="string">'No flash response, applying .'</span> + swfCSS.swfTimedout + <span class="string">' CSS...'</span>,
    fbLoaded: <span class="string">'Flash loaded'</span>,
    fbHandler: smc + <span class="string">'flashBlockHandler()'</span>,
    manURL: <span class="string">'SMSound.load(): Using manually-assigned URL'</span>,
    onURL: sm + <span class="string">'.load(): current URL already assigned.'</span>,
    badFV: sm + <span class="string">'.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.'</span>,
    as2loop: <span class="string">'Note: Setting stream:false so looping can work (flash 8 limitation)'</span>,
    noNSLoop: <span class="string">'Note: Looping not implemented for MovieStar formats'</span>,
    needfl9: <span class="string">'Note: Switching to flash 9, required for MP4 formats.'</span>,
    mfTimeout: <span class="string">'Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case'</span>,
    needFlash: smc + <span class="string">'Fatal error: Flash is needed to play some required formats, but is not available.'</span>,
    gotFocus: smc + <span class="string">'Got window focus.'</span>,
    policy: <span class="string">'Enabling usePolicyFile for data access'</span>,
    setup: sm + <span class="string">'.setup(): allowed parameters: %s'</span>,
    setupError: sm + <span class="string">'.setup(): "%s" cannot be assigned with this method.'</span>,
    setupUndef: sm + <span class="string">'.setup(): Could not find option "%s"'</span>,
    setupLate: sm + <span class="string">'.setup(): url, flashVersion and html5Test property changes will not take effect until reboot().'</span>,
    noURL: smc + <span class="string">'Flash URL required. Call soundManager.setup({url:...}) to get started.'</span>,
    sm2Loaded: <span class="string">'SoundManager 2: Ready. '</span> + String.fromCharCode(<span class="number">10003</span>),
    reset: sm + <span class="string">'.reset(): Removing event callbacks'</span>,
    mobileUA: <span class="string">'Mobile UA detected, preferring HTML5 by default.'</span>,
    globalHTML5: <span class="string">'Using singleton HTML5 Audio() pattern for this device.'</span>,
    ignoreMobile: <span class="string">'Ignoring mobile restrictions for this device.'</span></pre></div></div>
            
        </li>
        
        
        <li id="section-326">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-326">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  str = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-327">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-327">&#182;</a>
              </div>
              <p>internal string replace helper.
arguments: o [,items to replace]</p>
<d>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> args,
        i, j, o,
        sstr;</pre></div></div>
            
        </li>
        
        
        <li id="section-328">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-328">&#182;</a>
              </div>
              <p>real array, please</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    args = slice.call(arguments);</pre></div></div>
            
        </li>
        
        
        <li id="section-329">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-329">&#182;</a>
              </div>
              <p>first argument</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    o = args.shift();

    sstr = (strings &amp;&amp; strings[o] ? strings[o] : <span class="string">''</span>);

    <span class="keyword">if</span> (sstr &amp;&amp; args &amp;&amp; args.length) {
      <span class="keyword">for</span> (i = <span class="number">0</span>, j = args.length; i &lt; j; i++) {
        sstr = sstr.replace(<span class="string">'%s'</span>, args[i]);
      }
    }

    <span class="keyword">return</span> sstr;</pre></div></div>
            
        </li>
        
        
        <li id="section-330">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-330">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  loopFix = <span class="keyword">function</span>(sOpt) {</pre></div></div>
            
        </li>
        
        
        <li id="section-331">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-331">&#182;</a>
              </div>
              <p>flash 8 requires stream = false for looping to work</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (fV === <span class="number">8</span> &amp;&amp; sOpt.loops &gt; <span class="number">1</span> &amp;&amp; sOpt.stream) {
      _wDS(<span class="string">'as2loop'</span>);
      sOpt.stream = <span class="literal">false</span>;
    }

    <span class="keyword">return</span> sOpt;

  };

  policyFix = <span class="keyword">function</span>(sOpt, sPre) {

    <span class="keyword">if</span> (sOpt &amp;&amp; !sOpt.usePolicyFile &amp;&amp; (sOpt.onid3 || sOpt.usePeakData || sOpt.useWaveformData || sOpt.useEQData)) {
      sm2._wD((sPre || <span class="string">''</span>) + str(<span class="string">'policy'</span>));
      sOpt.usePolicyFile = <span class="literal">true</span>;
    }

    <span class="keyword">return</span> sOpt;

  };

  complain = <span class="keyword">function</span>(sMsg) {</pre></div></div>
            
        </li>
        
        
        <li id="section-332">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-332">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (hasConsole &amp;&amp; console.warn !== _<span class="literal">undefined</span>) {
      console.warn(sMsg);
    } <span class="keyword">else</span> {
      sm2._wD(sMsg);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-333">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-333">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  doNothing = <span class="keyword">function</span>() {

    <span class="keyword">return</span> <span class="literal">false</span>;

  };

  disableObject = <span class="keyword">function</span>(o) {

    <span class="keyword">var</span> oProp;

    <span class="keyword">for</span> (oProp <span class="keyword">in</span> o) {
      <span class="keyword">if</span> (o.hasOwnProperty(oProp) &amp;&amp; <span class="keyword">typeof</span> o[oProp] === <span class="string">'function'</span>) {
        o[oProp] = doNothing;
      }
    }

    oProp = <span class="literal">null</span>;

  };

  failSafely = <span class="keyword">function</span>(bNoDisable) {</pre></div></div>
            
        </li>
        
        
        <li id="section-334">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-334">&#182;</a>
              </div>
              <p>general failure exception handler</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (bNoDisable === _<span class="literal">undefined</span>) {
      bNoDisable = <span class="literal">false</span>;
    }

    <span class="keyword">if</span> (disabled || bNoDisable) {
      sm2.disable(bNoDisable);
    }

  };

  normalizeMovieURL = <span class="keyword">function</span>(movieURL) {

    <span class="keyword">var</span> urlParams = <span class="literal">null</span>, url;

    <span class="keyword">if</span> (movieURL) {

      <span class="keyword">if</span> (movieURL.match(<span class="regexp">/\.swf(\?.*)?$/i</span>)) {

        urlParams = movieURL.substr(movieURL.toLowerCase().lastIndexOf(<span class="string">'.swf?'</span>) + <span class="number">4</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-335">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-335">&#182;</a>
              </div>
              <p>assume user knows what they&#39;re doing</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (urlParams) <span class="keyword">return</span> movieURL;

      } <span class="keyword">else</span> <span class="keyword">if</span> (movieURL.lastIndexOf(<span class="string">'/'</span>) !== movieURL.length - <span class="number">1</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-336">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-336">&#182;</a>
              </div>
              <p>append trailing slash, if needed</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        movieURL += <span class="string">'/'</span>;

      }

    }

    url = (movieURL &amp;&amp; movieURL.lastIndexOf(<span class="string">'/'</span>) !== -<span class="number">1</span> ? movieURL.substr(<span class="number">0</span>, movieURL.lastIndexOf(<span class="string">'/'</span>) + <span class="number">1</span>) : <span class="string">'./'</span>) + sm2.movieURL;

    <span class="keyword">if</span> (sm2.noSWFCache) {
      url += (<span class="string">'?ts='</span> + <span class="keyword">new</span> Date().getTime());
    }

    <span class="keyword">return</span> url;

  };

  setVersionInfo = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-337">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-337">&#182;</a>
              </div>
              <p>short-hand for internal use</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    fV = parseInt(sm2.flashVersion, <span class="number">10</span>);

    <span class="keyword">if</span> (fV !== <span class="number">8</span> &amp;&amp; fV !== <span class="number">9</span>) {
      sm2._wD(str(<span class="string">'badFV'</span>, fV, defaultFlashVersion));
      sm2.flashVersion = fV = defaultFlashVersion;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-338">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-338">&#182;</a>
              </div>
              <p>debug flash movie, if applicable</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> isDebug = (sm2.debugMode || sm2.debugFlash ? <span class="string">'_debug.swf'</span> : <span class="string">'.swf'</span>);

    <span class="keyword">if</span> (sm2.useHTML5Audio &amp;&amp; !sm2.html5Only &amp;&amp; sm2.audioFormats.mp4.required &amp;&amp; fV &lt; <span class="number">9</span>) {
      sm2._wD(str(<span class="string">'needfl9'</span>));
      sm2.flashVersion = fV = <span class="number">9</span>;
    }

    sm2.version = sm2.versionNumber + (sm2.html5Only ? <span class="string">' (HTML5-only mode)'</span> : (fV === <span class="number">9</span> ? <span class="string">' (AS3/Flash 9)'</span> : <span class="string">' (AS2/Flash 8)'</span>));</pre></div></div>
            
        </li>
        
        
        <li id="section-339">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-339">&#182;</a>
              </div>
              <p>set up default options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (fV &gt; <span class="number">8</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-340">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-340">&#182;</a>
              </div>
              <p>+flash 9 base options</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.defaultOptions = mixin(sm2.defaultOptions, sm2.flash9Options);
      sm2.features.buffering = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-341">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-341">&#182;</a>
              </div>
              <p>+moviestar support</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.defaultOptions = mixin(sm2.defaultOptions, sm2.movieStarOptions);
      sm2.filePatterns.flash9 = <span class="keyword">new</span> RegExp(<span class="string">'\\.(mp3|'</span> + netStreamTypes.join(<span class="string">'|'</span>) + <span class="string">')(\\?.*)?$'</span>, <span class="string">'i'</span>);
      sm2.features.movieStar = <span class="literal">true</span>;

    } <span class="keyword">else</span> {

      sm2.features.movieStar = <span class="literal">false</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-342">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-342">&#182;</a>
              </div>
              <p>regExp for flash canPlay(), etc.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    sm2.filePattern = sm2.filePatterns[(fV !== <span class="number">8</span> ? <span class="string">'flash9'</span> : <span class="string">'flash8'</span>)];</pre></div></div>
            
        </li>
        
        
        <li id="section-343">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-343">&#182;</a>
              </div>
              <p>if applicable, use _debug versions of SWFs</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    sm2.movieURL = (fV === <span class="number">8</span> ? <span class="string">'soundmanager2.swf'</span> : <span class="string">'soundmanager2_flash9.swf'</span>).replace(<span class="string">'.swf'</span>, isDebug);

    sm2.features.peakData = sm2.features.waveformData = sm2.features.eqData = (fV &gt; <span class="number">8</span>);

  };

  setPolling = <span class="keyword">function</span>(bPolling, bHighPerformance) {

    <span class="keyword">if</span> (!flash) {
      <span class="keyword">return</span>;
    }

    flash._setPolling(bPolling, bHighPerformance);

  };

  initDebug = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-344">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-344">&#182;</a>
              </div>
              <p>starts debug mode, creating output <div> for UAs without console object</p>

            </div>
            
        </li>
        
        
        <li id="section-345">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-345">&#182;</a>
              </div>
              <p>allow force of debug mode via URL</p>
<d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (sm2.debugURLParam.test(wl)) {
      sm2.setupOptions.debugMode = sm2.debugMode = <span class="literal">true</span>;
    }

    <span class="keyword">if</span> (id(sm2.debugID)) {
      <span class="keyword">return</span>;
    }

    <span class="keyword">var</span> oD, oDebug, oTarget, oToggle, tmp;

    <span class="keyword">if</span> (sm2.debugMode &amp;&amp; !id(sm2.debugID) &amp;&amp; (!hasConsole || !sm2.useConsole || !sm2.consoleOnly)) {

      oD = doc.createElement(<span class="string">'div'</span>);
      oD.id = sm2.debugID + <span class="string">'-toggle'</span>;

      oToggle = {
        position: <span class="string">'fixed'</span>,
        bottom: <span class="string">'0px'</span>,
        right: <span class="string">'0px'</span>,
        width: <span class="string">'1.2em'</span>,
        height: <span class="string">'1.2em'</span>,
        lineHeight: <span class="string">'1.2em'</span>,
        margin: <span class="string">'2px'</span>,
        textAlign: <span class="string">'center'</span>,
        border: <span class="string">'1px solid #999'</span>,
        cursor: <span class="string">'pointer'</span>,
        background: <span class="string">'#fff'</span>,
        color: <span class="string">'#333'</span>,
        zIndex: <span class="number">10001</span>
      };

      oD.appendChild(doc.createTextNode(<span class="string">'-'</span>));
      oD.onclick = toggleDebug;
      oD.title = <span class="string">'Toggle SM2 debug console'</span>;

      <span class="keyword">if</span> (ua.match(<span class="regexp">/msie 6/i</span>)) {
        oD.style.position = <span class="string">'absolute'</span>;
        oD.style.cursor = <span class="string">'hand'</span>;
      }

      <span class="keyword">for</span> (tmp <span class="keyword">in</span> oToggle) {
        <span class="keyword">if</span> (oToggle.hasOwnProperty(tmp)) {
          oD.style[tmp] = oToggle[tmp];
        }
      }

      oDebug = doc.createElement(<span class="string">'div'</span>);
      oDebug.id = sm2.debugID;
      oDebug.style.display = (sm2.debugMode ? <span class="string">'block'</span> : <span class="string">'none'</span>);

      <span class="keyword">if</span> (sm2.debugMode &amp;&amp; !id(oD.id)) {
        <span class="keyword">try</span> {
          oTarget = getDocument();
          oTarget.appendChild(oD);
        } <span class="keyword">catch</span>(e2) {
          <span class="keyword">throw</span> <span class="keyword">new</span> Error(str(<span class="string">'domError'</span>) + <span class="string">' \n'</span> + e2.toString());
        }
        oTarget.appendChild(oDebug);
      }

    }

    oTarget = <span class="literal">null</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-346">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-346">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  idCheck = <span class="keyword">this</span>.getSoundById;</pre></div></div>
            
        </li>
        
        
        <li id="section-347">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-347">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>  _wDS = <span class="keyword">function</span>(o, errorLevel) {

    <span class="keyword">return</span> (!o ? <span class="string">''</span> : sm2._wD(str(o), errorLevel));

  };

  toggleDebug = <span class="keyword">function</span>() {

    <span class="keyword">var</span> o = id(sm2.debugID),
    oT = id(sm2.debugID + <span class="string">'-toggle'</span>);

    <span class="keyword">if</span> (!o) {
      <span class="keyword">return</span>;
    }

    <span class="keyword">if</span> (debugOpen) {</pre></div></div>
            
        </li>
        
        
        <li id="section-348">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-348">&#182;</a>
              </div>
              <p>minimize</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      oT.innerHTML = <span class="string">'+'</span>;
      o.style.display = <span class="string">'none'</span>;
    } <span class="keyword">else</span> {
      oT.innerHTML = <span class="string">'-'</span>;
      o.style.display = <span class="string">'block'</span>;
    }

    debugOpen = !debugOpen;

  };

  debugTS = <span class="keyword">function</span>(sEventType, bSuccess, sMessage) {</pre></div></div>
            
        </li>
        
        
        <li id="section-349">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-349">&#182;</a>
              </div>
              <p>troubleshooter debug hooks</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (window.sm2Debugger !== _<span class="literal">undefined</span>) {
      <span class="keyword">try</span> {
        sm2Debugger.handleEvent(sEventType, bSuccess, sMessage);
      } <span class="keyword">catch</span>(e) {</pre></div></div>
            
        </li>
        
        
        <li id="section-350">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-350">&#182;</a>
              </div>
              <p>oh well</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">return</span> <span class="literal">false</span>;
      }
    }

    <span class="keyword">return</span> <span class="literal">true</span>;

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-351">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-351">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  getSWFCSS = <span class="keyword">function</span>() {

    <span class="keyword">var</span> css = [];

    <span class="keyword">if</span> (sm2.debugMode) {
      css.push(swfCSS.sm2Debug);
    }

    <span class="keyword">if</span> (sm2.debugFlash) {
      css.push(swfCSS.flashDebug);
    }

    <span class="keyword">if</span> (sm2.useHighPerformance) {
      css.push(swfCSS.highPerf);
    }

    <span class="keyword">return</span> css.join(<span class="string">' '</span>);

  };

  flashBlockHandler = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-352">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-352">&#182;</a>
              </div>
              <p><em>possible</em> flash block situation.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">var</span> name = str(<span class="string">'fbHandler'</span>),
        p = sm2.getMoviePercent(),
        css = swfCSS,
        error = {
          type: <span class="string">'FLASHBLOCK'</span>
        };

    <span class="keyword">if</span> (sm2.html5Only) {</pre></div></div>
            
        </li>
        
        
        <li id="section-353">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-353">&#182;</a>
              </div>
              <p>no flash, or unused</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">return</span>;
    }

    <span class="keyword">if</span> (!sm2.ok()) {

      <span class="keyword">if</span> (needsFlash) {</pre></div></div>
            
        </li>
        
        
        <li id="section-354">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-354">&#182;</a>
              </div>
              <p>make the movie more visible, so user can fix</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sm2.oMC.className = getSWFCSS() + <span class="string">' '</span> + css.swfDefault + <span class="string">' '</span> + (p === <span class="literal">null</span> ? css.swfTimedout : css.swfError);
        sm2._wD(name + <span class="string">': '</span> + str(<span class="string">'fbTimeout'</span>) + (p ? <span class="string">' ('</span> + str(<span class="string">'fbLoaded'</span>) + <span class="string">')'</span> : <span class="string">''</span>));
      }

      sm2.didFlashBlock = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-355">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-355">&#182;</a>
              </div>
              <p>fire onready(), complain lightly</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      processOnEvents({
        type: <span class="string">'ontimeout'</span>,
        ignoreInit: <span class="literal">true</span>,
        error: error
      });

      catchError(error);

    } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-356">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-356">&#182;</a>
              </div>
              <p>SM2 loaded OK (or recovered)</p>

            </div>
            
        </li>
        
        
        <li id="section-357">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-357">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (sm2.didFlashBlock) {
        sm2._wD(name + <span class="string">': Unblocked'</span>);
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-358">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-358">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (sm2.oMC) {
        sm2.oMC.className = [getSWFCSS(), css.swfDefault, css.swfLoaded + (sm2.didFlashBlock ? <span class="string">' '</span> + css.swfUnblocked : <span class="string">''</span>)].join(<span class="string">' '</span>);
      }

    }

  };

  addOnEvent = <span class="keyword">function</span>(sType, oMethod, oScope) {

    <span class="keyword">if</span> (on_queue[sType] === _<span class="literal">undefined</span>) {
      on_queue[sType] = [];
    }

    on_queue[sType].push({
      method: oMethod,
      scope: (oScope || <span class="literal">null</span>),
      fired: <span class="literal">false</span>
    });

  };

  processOnEvents = <span class="keyword">function</span>(oOptions) {</pre></div></div>
            
        </li>
        
        
        <li id="section-359">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-359">&#182;</a>
              </div>
              <p>if unspecified, assume OK/error</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (!oOptions) {
      oOptions = {
        type: (sm2.ok() ? <span class="string">'onready'</span> : <span class="string">'ontimeout'</span>)
      };
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-360">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-360">&#182;</a>
              </div>
              <p>not ready yet.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (!didInit &amp;&amp; oOptions &amp;&amp; !oOptions.ignoreInit) <span class="keyword">return</span> <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-361">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-361">&#182;</a>
              </div>
              <p>invalid case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (oOptions.type === <span class="string">'ontimeout'</span> &amp;&amp; (sm2.ok() || (disabled &amp;&amp; !oOptions.ignoreInit))) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">var</span> status = {
          success: (oOptions &amp;&amp; oOptions.ignoreInit ? sm2.ok() : !disabled)
        },</pre></div></div>
            
        </li>
        
        
        <li id="section-362">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-362">&#182;</a>
              </div>
              <p>queue specified by type, or none</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        srcQueue = (oOptions &amp;&amp; oOptions.type ? on_queue[oOptions.type] || [] : []),

        queue = [], i, j,
        args = [status],
        canRetry = (needsFlash &amp;&amp; !sm2.ok());

    <span class="keyword">if</span> (oOptions.error) {
      args[<span class="number">0</span>].error = oOptions.error;
    }

    <span class="keyword">for</span> (i = <span class="number">0</span>, j = srcQueue.length; i &lt; j; i++) {
      <span class="keyword">if</span> (srcQueue[i].fired !== <span class="literal">true</span>) {
        queue.push(srcQueue[i]);
      }
    }

    <span class="keyword">if</span> (queue.length) {</pre></div></div>
            
        </li>
        
        
        <li id="section-363">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-363">&#182;</a>
              </div>
              <p>sm2._wD(sm + &#39;: Firing &#39; + queue.length + &#39; &#39; + oOptions.type + &#39;() item&#39; + (queue.length === 1 ? &#39;&#39; : &#39;s&#39;));</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">for</span> (i = <span class="number">0</span>, j = queue.length; i &lt; j; i++) {

        <span class="keyword">if</span> (queue[i].scope) {
          queue[i].method.apply(queue[i].scope, args);
        } <span class="keyword">else</span> {
          queue[i].method.apply(<span class="keyword">this</span>, args);
        }

        <span class="keyword">if</span> (!canRetry) {</pre></div></div>
            
        </li>
        
        
        <li id="section-364">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-364">&#182;</a>
              </div>
              <p>useFlashBlock and SWF timeout case doesn&#39;t count here.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          queue[i].fired = <span class="literal">true</span>;

        }

      }

    }

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  initUserOnload = <span class="keyword">function</span>() {

    window.setTimeout(<span class="keyword">function</span>() {

      <span class="keyword">if</span> (sm2.useFlashBlock) {
        flashBlockHandler();
      }

      processOnEvents();</pre></div></div>
            
        </li>
        
        
        <li id="section-365">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-365">&#182;</a>
              </div>
              <p>call user-defined &quot;onload&quot;, scoped to window</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (<span class="keyword">typeof</span> sm2.onload === <span class="string">'function'</span>) {
        _wDS(<span class="string">'onload'</span>, <span class="number">1</span>);
        sm2.onload.apply(window);
        _wDS(<span class="string">'onloadOK'</span>, <span class="number">1</span>);
      }

      <span class="keyword">if</span> (sm2.waitForWindowLoad) {
        event.add(window, <span class="string">'load'</span>, initUserOnload);
      }

    }, <span class="number">1</span>);

  };

  detectFlash = <span class="keyword">function</span>() {

    <span class="comment">/**
     * Hat tip: Flash Detect library (BSD, (C) 2007) by Carl "DocYes" S. Yestrau
     * http://featureblend.com/javascript-flash-detection-library.html / http://featureblend.com/license.txt
     */</span></pre></div></div>
            
        </li>
        
        
        <li id="section-366">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-366">&#182;</a>
              </div>
              <p>this work has already been done.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (hasFlash !== _<span class="literal">undefined</span>) <span class="keyword">return</span> hasFlash;

    <span class="keyword">var</span> hasPlugin = <span class="literal">false</span>, n = navigator, obj, type, types, AX = window.ActiveXObject;</pre></div></div>
            
        </li>
        
        
        <li id="section-367">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-367">&#182;</a>
              </div>
              <p>MS Edge 14 throws an &quot;Unspecified Error&quot; because n.plugins is inaccessible due to permissions</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> nP;

    <span class="keyword">try</span> {
      nP = n.plugins;
    } <span class="keyword">catch</span>(e) {
      nP = <span class="literal">undefined</span>;
    }

    <span class="keyword">if</span> (nP &amp;&amp; nP.length) {

      type = <span class="string">'application/x-shockwave-flash'</span>;
      types = n.mimeTypes;

      <span class="keyword">if</span> (types &amp;&amp; types[type] &amp;&amp; types[type].enabledPlugin &amp;&amp; types[type].enabledPlugin.description) {
        hasPlugin = <span class="literal">true</span>;
      }

    } <span class="keyword">else</span> <span class="keyword">if</span> (AX !== _<span class="literal">undefined</span> &amp;&amp; !ua.match(<span class="regexp">/MSAppHost/i</span>)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-368">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-368">&#182;</a>
              </div>
              <p>Windows 8 Store Apps (MSAppHost) are weird (compatibility?) and won&#39;t complain here, but will barf if Flash/ActiveX object is appended to the DOM.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">try</span> {
        obj = <span class="keyword">new</span> AX(<span class="string">'ShockwaveFlash.ShockwaveFlash'</span>);
      } <span class="keyword">catch</span>(e) {</pre></div></div>
            
        </li>
        
        
        <li id="section-369">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-369">&#182;</a>
              </div>
              <p>oh well</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        obj = <span class="literal">null</span>;
      }

      hasPlugin = (!!obj);</pre></div></div>
            
        </li>
        
        
        <li id="section-370">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-370">&#182;</a>
              </div>
              <p>cleanup, because it is ActiveX after all</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      obj = <span class="literal">null</span>;

    }

    hasFlash = hasPlugin;

    <span class="keyword">return</span> hasPlugin;

  };

  featureCheck = <span class="keyword">function</span>() {

    <span class="keyword">var</span> flashNeeded,
        item,
        formats = sm2.audioFormats,</pre></div></div>
            
        </li>
        
        
        <li id="section-371">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-371">&#182;</a>
              </div>
              <p>iPhone &lt;= 3.1 has broken HTML5 audio(), but firmware 3.2 (original iPad) + iOS4 works.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        isSpecial = (is_iDevice &amp;&amp; !!(ua.match(<span class="regexp">/os (1|2|3_0|3_1)\s/i</span>)));

    <span class="keyword">if</span> (isSpecial) {</pre></div></div>
            
        </li>
        
        
        <li id="section-372">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-372">&#182;</a>
              </div>
              <p>has Audio(), but is broken; let it load links directly.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.hasHTML5 = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-373">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-373">&#182;</a>
              </div>
              <p>ignore flash case, however</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.html5Only = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-374">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-374">&#182;</a>
              </div>
              <p>hide the SWF, if present</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (sm2.oMC) {
        sm2.oMC.style.display = <span class="string">'none'</span>;
      }

    } <span class="keyword">else</span> <span class="keyword">if</span> (sm2.useHTML5Audio) {

        <span class="keyword">if</span> (!sm2.html5 || !sm2.html5.canPlayType) {
          sm2._wD(<span class="string">'SoundManager: No HTML5 Audio() support detected.'</span>);
          sm2.hasHTML5 = <span class="literal">false</span>;
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-375">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-375">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (isBadSafari) {
          sm2._wD(smc + <span class="string">'Note: Buggy HTML5 Audio in Safari on this OS X release, see https://bugs.webkit.org/show_bug.cgi?id=32159 - '</span> + (!hasFlash ? <span class="string">' would use flash fallback for MP3/MP4, but none detected.'</span> : <span class="string">'will use flash fallback for MP3/MP4, if available'</span>), <span class="number">1</span>);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-376">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-376">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      }

    <span class="keyword">if</span> (sm2.useHTML5Audio &amp;&amp; sm2.hasHTML5) {</pre></div></div>
            
        </li>
        
        
        <li id="section-377">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-377">&#182;</a>
              </div>
              <p>sort out whether flash is optional, required or can be ignored.</p>

            </div>
            
        </li>
        
        
        <li id="section-378">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-378">&#182;</a>
              </div>
              <p>innocent until proven guilty.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      canIgnoreFlash = <span class="literal">true</span>;

      <span class="keyword">for</span> (item <span class="keyword">in</span> formats) {

        <span class="keyword">if</span> (formats.hasOwnProperty(item)) {

          <span class="keyword">if</span> (formats[item].required) {

            <span class="keyword">if</span> (!sm2.html5.canPlayType(formats[item].type)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-379">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-379">&#182;</a>
              </div>
              <p>100% HTML5 mode is not possible.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              canIgnoreFlash = <span class="literal">false</span>;
              flashNeeded = <span class="literal">true</span>;

            } <span class="keyword">else</span> <span class="keyword">if</span> (sm2.preferFlash &amp;&amp; (sm2.flash[item] || sm2.flash[formats[item].type])) {</pre></div></div>
            
        </li>
        
        
        <li id="section-380">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-380">&#182;</a>
              </div>
              <p>flash may be required, or preferred for this format.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>              flashNeeded = <span class="literal">true</span>;

            }

          }

        }

      }

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-381">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-381">&#182;</a>
              </div>
              <p>sanity check...</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (sm2.ignoreFlash) {
      flashNeeded = <span class="literal">false</span>;
      canIgnoreFlash = <span class="literal">true</span>;
    }

    sm2.html5Only = (sm2.hasHTML5 &amp;&amp; sm2.useHTML5Audio &amp;&amp; !flashNeeded);

    <span class="keyword">return</span> (!sm2.html5Only);

  };

  parseURL = <span class="keyword">function</span>(url) {

    <span class="comment">/**
     * Internal: Finds and returns the first playable URL (or failing that, the first URL.)
     * @param {string or array} url A single URL string, OR, an array of URL strings or {url:'/path/to/resource', type:'audio/mp3'} objects.
     */</span>

    <span class="keyword">var</span> i, j, urlResult = <span class="number">0</span>, result;

    <span class="keyword">if</span> (url <span class="keyword">instanceof</span> Array) {</pre></div></div>
            
        </li>
        
        
        <li id="section-382">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-382">&#182;</a>
              </div>
              <p>find the first good one</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">for</span> (i = <span class="number">0</span>, j = url.length; i &lt; j; i++) {

        <span class="keyword">if</span> (url[i] <span class="keyword">instanceof</span> Object) {</pre></div></div>
            
        </li>
        
        
        <li id="section-383">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-383">&#182;</a>
              </div>
              <p>MIME check</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (sm2.canPlayMIME(url[i].type)) {
            urlResult = i;
            <span class="keyword">break</span>;
          }

        } <span class="keyword">else</span> <span class="keyword">if</span> (sm2.canPlayURL(url[i])) {</pre></div></div>
            
        </li>
        
        
        <li id="section-384">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-384">&#182;</a>
              </div>
              <p>URL string check</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          urlResult = i;
          <span class="keyword">break</span>;

        }

      }</pre></div></div>
            
        </li>
        
        
        <li id="section-385">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-385">&#182;</a>
              </div>
              <p>normalize to string</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (url[urlResult].url) {
        url[urlResult] = url[urlResult].url;
      }

      result = url[urlResult];

    } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-386">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-386">&#182;</a>
              </div>
              <p>single URL case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      result = url;

    }

    <span class="keyword">return</span> result;

  };


  startTimer = <span class="keyword">function</span>(oSound) {

    <span class="comment">/**
     * attach a timer to this sound, and start an interval if needed
     */</span>

    <span class="keyword">if</span> (!oSound._hasTimer) {

      oSound._hasTimer = <span class="literal">true</span>;

      <span class="keyword">if</span> (!mobileHTML5 &amp;&amp; sm2.html5PollingInterval) {

        <span class="keyword">if</span> (h5IntervalTimer === <span class="literal">null</span> &amp;&amp; h5TimerCount === <span class="number">0</span>) {

          h5IntervalTimer = setInterval(timerExecute, sm2.html5PollingInterval);

        }

        h5TimerCount++;

      }

    }

  };

  stopTimer = <span class="keyword">function</span>(oSound) {

    <span class="comment">/**
     * detach a timer
     */</span>

    <span class="keyword">if</span> (oSound._hasTimer) {

      oSound._hasTimer = <span class="literal">false</span>;

      <span class="keyword">if</span> (!mobileHTML5 &amp;&amp; sm2.html5PollingInterval) {</pre></div></div>
            
        </li>
        
        
        <li id="section-387">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-387">&#182;</a>
              </div>
              <p>interval will stop itself at next execution.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        h5TimerCount--;

      }

    }

  };

  timerExecute = <span class="keyword">function</span>() {

    <span class="comment">/**
     * manual polling for HTML5 progress events, ie., whileplaying()
     * (can achieve greater precision than conservative default HTML5 interval)
     */</span>

    <span class="keyword">var</span> i;

    <span class="keyword">if</span> (h5IntervalTimer !== <span class="literal">null</span> &amp;&amp; !h5TimerCount) {</pre></div></div>
            
        </li>
        
        
        <li id="section-388">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-388">&#182;</a>
              </div>
              <p>no active timers, stop polling interval.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      clearInterval(h5IntervalTimer);

      h5IntervalTimer = <span class="literal">null</span>;

      <span class="keyword">return</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-389">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-389">&#182;</a>
              </div>
              <p>check all HTML5 sounds with timers</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">for</span> (i = sm2.soundIDs.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {

      <span class="keyword">if</span> (sm2.sounds[sm2.soundIDs[i]].isHTML5 &amp;&amp; sm2.sounds[sm2.soundIDs[i]]._hasTimer) {
        sm2.sounds[sm2.soundIDs[i]]._onTimer();
      }

    }

  };

  catchError = <span class="keyword">function</span>(options) {

    options = (options !== _<span class="literal">undefined</span> ? options : {});

    <span class="keyword">if</span> (<span class="keyword">typeof</span> sm2.onerror === <span class="string">'function'</span>) {
      sm2.onerror.apply(window, [{
        type: (options.type !== _<span class="literal">undefined</span> ? options.type : <span class="literal">null</span>)
      }]);
    }

    <span class="keyword">if</span> (options.fatal !== _<span class="literal">undefined</span> &amp;&amp; options.fatal) {
      sm2.disable();
    }

  };

  badSafariFix = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-390">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-390">&#182;</a>
              </div>
              <p>special case: &quot;bad&quot; Safari (OS X 10.3 - 10.7) must fall back to flash for MP3/MP4</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (!isBadSafari || !detectFlash()) {</pre></div></div>
            
        </li>
        
        
        <li id="section-391">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-391">&#182;</a>
              </div>
              <p>doesn&#39;t apply</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">return</span>;
    }

    <span class="keyword">var</span> aF = sm2.audioFormats, i, item;

    <span class="keyword">for</span> (item <span class="keyword">in</span> aF) {

      <span class="keyword">if</span> (aF.hasOwnProperty(item)) {

        <span class="keyword">if</span> (item === <span class="string">'mp3'</span> || item === <span class="string">'mp4'</span>) {

          sm2._wD(sm + <span class="string">': Using flash fallback for '</span> + item + <span class="string">' format'</span>);
          sm2.html5[item] = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-392">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-392">&#182;</a>
              </div>
              <p>assign result to related formats, too</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          <span class="keyword">if</span> (aF[item] &amp;&amp; aF[item].related) {
            <span class="keyword">for</span> (i = aF[item].related.length - <span class="number">1</span>; i &gt;= <span class="number">0</span>; i--) {
              sm2.html5[aF[item].related[i]] = <span class="literal">false</span>;
            }
          }

        }

      }

    }

  };

  <span class="comment">/**
   * Pseudo-private flash/ExternalInterface methods
   * ----------------------------------------------
   */</span>

  <span class="keyword">this</span>._setSandboxType = <span class="keyword">function</span>(sandboxType) {</pre></div></div>
            
        </li>
        
        
        <li id="section-393">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-393">&#182;</a>
              </div>
              <p><d>
Security sandbox according to Flash plugin</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> sb = sm2.sandbox;

    sb.type = sandboxType;
    sb.description = sb.types[(sb.types[sandboxType] !== _<span class="literal">undefined</span> ? sandboxType : <span class="string">'unknown'</span>)];

    <span class="keyword">if</span> (sb.type === <span class="string">'localWithFile'</span>) {

      sb.noRemote = <span class="literal">true</span>;
      sb.noLocal = <span class="literal">false</span>;
      _wDS(<span class="string">'secNote'</span>, <span class="number">2</span>);

    } <span class="keyword">else</span> <span class="keyword">if</span> (sb.type === <span class="string">'localWithNetwork'</span>) {

      sb.noRemote = <span class="literal">false</span>;
      sb.noLocal = <span class="literal">true</span>;

    } <span class="keyword">else</span> <span class="keyword">if</span> (sb.type === <span class="string">'localTrusted'</span>) {

      sb.noRemote = <span class="literal">false</span>;
      sb.noLocal = <span class="literal">false</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-394">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-394">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  <span class="keyword">this</span>._externalInterfaceOK = <span class="keyword">function</span>(swfVersion) {</pre></div></div>
            
        </li>
        
        
        <li id="section-395">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-395">&#182;</a>
              </div>
              <p>flash callback confirming flash loaded, EI working etc.
swfVersion: SWF build string</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (sm2.swfLoaded) {
      <span class="keyword">return</span>;
    }

    <span class="keyword">var</span> e;

    debugTS(<span class="string">'swf'</span>, <span class="literal">true</span>);
    debugTS(<span class="string">'flashtojs'</span>, <span class="literal">true</span>);
    sm2.swfLoaded = <span class="literal">true</span>;
    tryInitOnFocus = <span class="literal">false</span>;

    <span class="keyword">if</span> (isBadSafari) {
      badSafariFix();
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-396">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-396">&#182;</a>
              </div>
              <p>complain if JS + SWF build/version strings don&#39;t match, excluding +DEV builds</p>
<d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (!swfVersion || swfVersion.replace(<span class="regexp">/\+dev/i</span>, <span class="string">''</span>) !== sm2.versionNumber.replace(<span class="regexp">/\+dev/i</span>, <span class="string">''</span>)) {

      e = sm + <span class="string">': Fatal: JavaScript file build "'</span> + sm2.versionNumber + <span class="string">'" does not match Flash SWF build "'</span> + swfVersion + <span class="string">'" at '</span> + sm2.url + <span class="string">'. Ensure both are up-to-date.'</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-397">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-397">&#182;</a>
              </div>
              <p>escape flash -&gt; JS stack so this error fires in window.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      setTimeout(<span class="keyword">function</span>() {
        <span class="keyword">throw</span> <span class="keyword">new</span> Error(e);
      }, <span class="number">0</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-398">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-398">&#182;</a>
              </div>
              <p>exit, init will fail with timeout</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">return</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-399">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-399">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
        </li>
        
        
        <li id="section-400">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-400">&#182;</a>
              </div>
              <p>IE needs a larger timeout</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    setTimeout(init, isIE ? <span class="number">100</span> : <span class="number">1</span>);

  };

  <span class="comment">/**
   * Private initialization helpers
   * ------------------------------
   */</span>

  createMovie = <span class="keyword">function</span>(movieID, movieURL) {</pre></div></div>
            
        </li>
        
        
        <li id="section-401">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-401">&#182;</a>
              </div>
              <p>ignore if already connected</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (didAppend &amp;&amp; appendSuccess) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="function"><span class="keyword">function</span> <span class="title">initMsg</span><span class="params">()</span> {</span></pre></div></div>
            
        </li>
        
        
        <li id="section-402">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-402">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">var</span> options = [],
          title,
          msg = [],
          delimiter = <span class="string">' + '</span>;

      title = <span class="string">'SoundManager '</span> + sm2.version + (!sm2.html5Only &amp;&amp; sm2.useHTML5Audio ? (sm2.hasHTML5 ? <span class="string">' + HTML5 audio'</span> : <span class="string">', no HTML5 audio support'</span>) : <span class="string">''</span>);

      <span class="keyword">if</span> (!sm2.html5Only) {

        <span class="keyword">if</span> (sm2.preferFlash) {
          options.push(<span class="string">'preferFlash'</span>);
        }

        <span class="keyword">if</span> (sm2.useHighPerformance) {
          options.push(<span class="string">'useHighPerformance'</span>);
        }

        <span class="keyword">if</span> (sm2.flashPollingInterval) {
          options.push(<span class="string">'flashPollingInterval ('</span> + sm2.flashPollingInterval + <span class="string">'ms)'</span>);
        }

        <span class="keyword">if</span> (sm2.html5PollingInterval) {
          options.push(<span class="string">'html5PollingInterval ('</span> + sm2.html5PollingInterval + <span class="string">'ms)'</span>);
        }

        <span class="keyword">if</span> (sm2.wmode) {
          options.push(<span class="string">'wmode ('</span> + sm2.wmode + <span class="string">')'</span>);
        }

        <span class="keyword">if</span> (sm2.debugFlash) {
          options.push(<span class="string">'debugFlash'</span>);
        }

        <span class="keyword">if</span> (sm2.useFlashBlock) {
          options.push(<span class="string">'flashBlock'</span>);
        }

      } <span class="keyword">else</span> <span class="keyword">if</span> (sm2.html5PollingInterval) {
          options.push(<span class="string">'html5PollingInterval ('</span> + sm2.html5PollingInterval + <span class="string">'ms)'</span>);
        }

      <span class="keyword">if</span> (options.length) {
        msg = msg.concat([options.join(delimiter)]);
      }

      sm2._wD(title + (msg.length ? delimiter + msg.join(<span class="string">', '</span>) : <span class="string">''</span>), <span class="number">1</span>);

      showSupport();</pre></div></div>
            
        </li>
        
        
        <li id="section-403">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-403">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    }

    <span class="keyword">if</span> (sm2.html5Only) {</pre></div></div>
            
        </li>
        
        
        <li id="section-404">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-404">&#182;</a>
              </div>
              <p>100% HTML5 mode</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      setVersionInfo();

      initMsg();
      sm2.oMC = id(sm2.movieID);
      init();</pre></div></div>
            
        </li>
        
        
        <li id="section-405">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-405">&#182;</a>
              </div>
              <p>prevent multiple init attempts</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      didAppend = <span class="literal">true</span>;

      appendSuccess = <span class="literal">true</span>;

      <span class="keyword">return</span> <span class="literal">false</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-406">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-406">&#182;</a>
              </div>
              <p>flash path</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">var</span> remoteURL = (movieURL || sm2.url),
    localURL = (sm2.altURL || remoteURL),
    swfTitle = <span class="string">'JS/Flash audio component (SoundManager 2)'</span>,
    oTarget = getDocument(),
    extraClass = getSWFCSS(),
    isRTL = <span class="literal">null</span>,
    html = doc.getElementsByTagName(<span class="string">'html'</span>)[<span class="number">0</span>],
    oEmbed, oMovie, tmp, movieHTML, oEl, s, x, sClass;

    isRTL = (html &amp;&amp; html.dir &amp;&amp; html.dir.match(<span class="regexp">/rtl/i</span>));
    movieID = (movieID === _<span class="literal">undefined</span> ? sm2.id : movieID);

    <span class="function"><span class="keyword">function</span> <span class="title">param</span><span class="params">(name, value)</span> {</span>
      <span class="keyword">return</span> <span class="string">'&lt;param name="'</span> + name + <span class="string">'" value="'</span> + value + <span class="string">'" /&gt;'</span>;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-407">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-407">&#182;</a>
              </div>
              <p>safety check for legacy (change to Flash 9 URL)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    setVersionInfo();
    sm2.url = normalizeMovieURL(overHTTP ? remoteURL : localURL);
    movieURL = sm2.url;

    sm2.wmode = (!sm2.wmode &amp;&amp; sm2.useHighPerformance ? <span class="string">'transparent'</span> : sm2.wmode);

    <span class="keyword">if</span> (sm2.wmode !== <span class="literal">null</span> &amp;&amp; (ua.match(<span class="regexp">/msie 8/i</span>) || (!isIE &amp;&amp; !sm2.useHighPerformance)) &amp;&amp; navigator.platform.match(<span class="regexp">/win32|win64/i</span>)) {
      <span class="comment">/**
       * extra-special case: movie doesn't load until scrolled into view when using wmode = anything but 'window' here
       * does not apply when using high performance (position:fixed means on-screen), OR infinite flash load timeout
       * wmode breaks IE 8 on Vista + Win7 too in some cases, as of January 2011 (?)
       */</span>
      messages.push(strings.spcWmode);
      sm2.wmode = <span class="literal">null</span>;
    }

    oEmbed = {
      name: movieID,
      id: movieID,
      src: movieURL,
      quality: <span class="string">'high'</span>,
      allowScriptAccess: sm2.allowScriptAccess,
      bgcolor: sm2.bgColor,
      pluginspage: http + <span class="string">'www.macromedia.com/go/getflashplayer'</span>,
      title: swfTitle,
      type: <span class="string">'application/x-shockwave-flash'</span>,
      wmode: sm2.wmode,</pre></div></div>
            
        </li>
        
        
        <li id="section-408">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-408">&#182;</a>
              </div>
              <p><a href="http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html">http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      hasPriority: <span class="string">'true'</span>
    };

    <span class="keyword">if</span> (sm2.debugFlash) {
      oEmbed.FlashVars = <span class="string">'debug=1'</span>;
    }

    <span class="keyword">if</span> (!sm2.wmode) {</pre></div></div>
            
        </li>
        
        
        <li id="section-409">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-409">&#182;</a>
              </div>
              <p>don&#39;t write empty attribute</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">delete</span> oEmbed.wmode;
    }

    <span class="keyword">if</span> (isIE) {</pre></div></div>
            
        </li>
        
        
        <li id="section-410">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-410">&#182;</a>
              </div>
              <p>IE is &quot;special&quot;.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      oMovie = doc.createElement(<span class="string">'div'</span>);
      movieHTML = [
        <span class="string">'&lt;object id="'</span> + movieID + <span class="string">'" data="'</span> + movieURL + <span class="string">'" type="'</span> + oEmbed.type + <span class="string">'" title="'</span> + oEmbed.title + <span class="string">'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;'</span>,
        param(<span class="string">'movie'</span>, movieURL),
        param(<span class="string">'AllowScriptAccess'</span>, sm2.allowScriptAccess),
        param(<span class="string">'quality'</span>, oEmbed.quality),
        (sm2.wmode ? param(<span class="string">'wmode'</span>, sm2.wmode) : <span class="string">''</span>),
        param(<span class="string">'bgcolor'</span>, sm2.bgColor),
        param(<span class="string">'hasPriority'</span>, <span class="string">'true'</span>),
        (sm2.debugFlash ? param(<span class="string">'FlashVars'</span>, oEmbed.FlashVars) : <span class="string">''</span>),
        <span class="string">'&lt;/object&gt;'</span>
      ].join(<span class="string">''</span>);

    } <span class="keyword">else</span> {

      oMovie = doc.createElement(<span class="string">'embed'</span>);
      <span class="keyword">for</span> (tmp <span class="keyword">in</span> oEmbed) {
        <span class="keyword">if</span> (oEmbed.hasOwnProperty(tmp)) {
          oMovie.setAttribute(tmp, oEmbed[tmp]);
        }
      }

    }

    initDebug();
    extraClass = getSWFCSS();
    oTarget = getDocument();

    <span class="keyword">if</span> (oTarget) {

      sm2.oMC = (id(sm2.movieID) || doc.createElement(<span class="string">'div'</span>));

      <span class="keyword">if</span> (!sm2.oMC.id) {

        sm2.oMC.id = sm2.movieID;
        sm2.oMC.className = swfCSS.swfDefault + <span class="string">' '</span> + extraClass;
        s = <span class="literal">null</span>;
        oEl = <span class="literal">null</span>;

        <span class="keyword">if</span> (!sm2.useFlashBlock) {
          <span class="keyword">if</span> (sm2.useHighPerformance) {</pre></div></div>
            
        </li>
        
        
        <li id="section-411">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-411">&#182;</a>
              </div>
              <p>on-screen at all times</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s = {
              position: <span class="string">'fixed'</span>,
              width: <span class="string">'8px'</span>,
              height: <span class="string">'8px'</span>,</pre></div></div>
            
        </li>
        
        
        <li id="section-412">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-412">&#182;</a>
              </div>
              <blockquote>
<p>= 6px for flash to run fast, &gt;= 8px to start up under Firefox/win32 in some cases. odd? yes.</p>
</blockquote>

            </div>
            
            <div class="content"><div class='highlight'><pre>              bottom: <span class="string">'0px'</span>,
              left: <span class="string">'0px'</span>,
              overflow: <span class="string">'hidden'</span>
            };
          } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-413">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-413">&#182;</a>
              </div>
              <p>hide off-screen, lower priority</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            s = {
              position: <span class="string">'absolute'</span>,
              width: <span class="string">'6px'</span>,
              height: <span class="string">'6px'</span>,
              top: <span class="string">'-9999px'</span>,
              left: <span class="string">'-9999px'</span>
            };
            <span class="keyword">if</span> (isRTL) {
              s.left = Math.abs(parseInt(s.left, <span class="number">10</span>)) + <span class="string">'px'</span>;
            }
          }
        }

        <span class="keyword">if</span> (isWebkit) {</pre></div></div>
            
        </li>
        
        
        <li id="section-414">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-414">&#182;</a>
              </div>
              <p>soundcloud-reported render/crash fix, safari 5</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2.oMC.style.zIndex = <span class="number">10000</span>;
        }

        <span class="keyword">if</span> (!sm2.debugFlash) {
          <span class="keyword">for</span> (x <span class="keyword">in</span> s) {
            <span class="keyword">if</span> (s.hasOwnProperty(x)) {
              sm2.oMC.style[x] = s[x];
            }
          }
        }

        <span class="keyword">try</span> {

          <span class="keyword">if</span> (!isIE) {
            sm2.oMC.appendChild(oMovie);
          }

          oTarget.appendChild(sm2.oMC);

          <span class="keyword">if</span> (isIE) {
            oEl = sm2.oMC.appendChild(doc.createElement(<span class="string">'div'</span>));
            oEl.className = swfCSS.swfBox;
            oEl.innerHTML = movieHTML;
          }

          appendSuccess = <span class="literal">true</span>;

        } <span class="keyword">catch</span>(e) {

          <span class="keyword">throw</span> <span class="keyword">new</span> Error(str(<span class="string">'domError'</span>) + <span class="string">' \n'</span> + e.toString());

        }

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-415">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-415">&#182;</a>
              </div>
              <p>SM2 container is already in the document (eg. flashblock use case)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        sClass = sm2.oMC.className;
        sm2.oMC.className = (sClass ? sClass + <span class="string">' '</span> : swfCSS.swfDefault) + (extraClass ? <span class="string">' '</span> + extraClass : <span class="string">''</span>);
        sm2.oMC.appendChild(oMovie);

        <span class="keyword">if</span> (isIE) {
          oEl = sm2.oMC.appendChild(doc.createElement(<span class="string">'div'</span>));
          oEl.className = swfCSS.swfBox;
          oEl.innerHTML = movieHTML;
        }

        appendSuccess = <span class="literal">true</span>;

      }

    }

    didAppend = <span class="literal">true</span>;

    initMsg();</pre></div></div>
            
        </li>
        
        
        <li id="section-416">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-416">&#182;</a>
              </div>
              <p>sm2._wD(sm + &#39;: Trying to load &#39; + movieURL + (!overHTTP &amp;&amp; sm2.altURL ? &#39; (alternate URL)&#39; : &#39;&#39;), 1);</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  initMovie = <span class="keyword">function</span>() {

    <span class="keyword">if</span> (sm2.html5Only) {
      createMovie();
      <span class="keyword">return</span> <span class="literal">false</span>;
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-417">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-417">&#182;</a>
              </div>
              <p>attempt to get, or create, movie (may already exist)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (flash) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">if</span> (!sm2.url) {

      <span class="comment">/**
       * Something isn't right - we've reached init, but the soundManager url property has not been set.
       * User has not called setup({url: ...}), or has not set soundManager.url (legacy use case) directly before init time.
       * Notify and exit. If user calls setup() with a url: property, init will be restarted as in the deferred loading case.
       */</span>

       _wDS(<span class="string">'noURL'</span>);
       <span class="keyword">return</span> <span class="literal">false</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-418">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-418">&#182;</a>
              </div>
              <p>inline markup case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    flash = sm2.getMovie(sm2.id);

    <span class="keyword">if</span> (!flash) {

      <span class="keyword">if</span> (!oRemoved) {</pre></div></div>
            
        </li>
        
        
        <li id="section-419">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-419">&#182;</a>
              </div>
              <p>try to create</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        createMovie(sm2.id, sm2.url);

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-420">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-420">&#182;</a>
              </div>
              <p>try to re-append removed movie after reboot()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (!isIE) {
          sm2.oMC.appendChild(oRemoved);
        } <span class="keyword">else</span> {
          sm2.oMC.innerHTML = oRemovedHTML;
        }

        oRemoved = <span class="literal">null</span>;
        didAppend = <span class="literal">true</span>;

      }

      flash = sm2.getMovie(sm2.id);

    }

    <span class="keyword">if</span> (<span class="keyword">typeof</span> sm2.oninitmovie === <span class="string">'function'</span>) {
      setTimeout(sm2.oninitmovie, <span class="number">1</span>);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-421">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-421">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>    flushMessages();</pre></div></div>
            
        </li>
        
        
        <li id="section-422">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-422">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  delayWaitForEI = <span class="keyword">function</span>() {

    setTimeout(waitForEI, <span class="number">1000</span>);

  };

  rebootIntoHTML5 = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-423">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-423">&#182;</a>
              </div>
              <p>special case: try for a reboot with preferFlash: false, if 100% HTML5 mode is possible and useFlashBlock is not enabled.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    window.setTimeout(<span class="keyword">function</span>() {

      complain(smc + <span class="string">'useFlashBlock is false, 100% HTML5 mode is possible. Rebooting with preferFlash: false...'</span>);

      sm2.setup({
        preferFlash: <span class="literal">false</span>
      }).reboot();</pre></div></div>
            
        </li>
        
        
        <li id="section-424">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-424">&#182;</a>
              </div>
              <p>if for some reason you want to detect this case, use an ontimeout() callback and look for html5Only and didFlashBlock == true.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.didFlashBlock = <span class="literal">true</span>;

      sm2.beginDelayedInit();

    }, <span class="number">1</span>);

  };

  waitForEI = <span class="keyword">function</span>() {

    <span class="keyword">var</span> p,
        loadIncomplete = <span class="literal">false</span>;

    <span class="keyword">if</span> (!sm2.url) {</pre></div></div>
            
        </li>
        
        
        <li id="section-425">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-425">&#182;</a>
              </div>
              <p>No SWF url to load (noURL case) - exit for now. Will be retried when url is set.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">return</span>;
    }

    <span class="keyword">if</span> (waitingForEI) {
      <span class="keyword">return</span>;
    }

    waitingForEI = <span class="literal">true</span>;
    event.remove(window, <span class="string">'load'</span>, delayWaitForEI);

    <span class="keyword">if</span> (hasFlash &amp;&amp; tryInitOnFocus &amp;&amp; !isFocused) {</pre></div></div>
            
        </li>
        
        
        <li id="section-426">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-426">&#182;</a>
              </div>
              <p>Safari won&#39;t load flash in background tabs, only when focused.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      _wDS(<span class="string">'waitFocus'</span>);
      <span class="keyword">return</span>;
    }

    <span class="keyword">if</span> (!didInit) {
      p = sm2.getMoviePercent();
      <span class="keyword">if</span> (p &gt; <span class="number">0</span> &amp;&amp; p &lt; <span class="number">100</span>) {
        loadIncomplete = <span class="literal">true</span>;
      }
    }

    setTimeout(<span class="keyword">function</span>() {

      p = sm2.getMoviePercent();

      <span class="keyword">if</span> (loadIncomplete) {</pre></div></div>
            
        </li>
        
        
        <li id="section-427">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-427">&#182;</a>
              </div>
              <p>special case: if movie <em>partially</em> loaded, retry until it&#39;s 100% before assuming failure.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        waitingForEI = <span class="literal">false</span>;
        sm2._wD(str(<span class="string">'waitSWF'</span>));
        window.setTimeout(delayWaitForEI, <span class="number">1</span>);
        <span class="keyword">return</span>;
      }</pre></div></div>
            
        </li>
        
        
        <li id="section-428">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-428">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>      <span class="keyword">if</span> (!didInit) {

        sm2._wD(sm + <span class="string">': No Flash response within expected time. Likely causes: '</span> + (p === <span class="number">0</span> ? <span class="string">'SWF load failed, '</span> : <span class="string">''</span>) + <span class="string">'Flash blocked or JS-Flash security error.'</span> + (sm2.debugFlash ? <span class="string">' '</span> + str(<span class="string">'checkSWF'</span>) : <span class="string">''</span>), <span class="number">2</span>);

        <span class="keyword">if</span> (!overHTTP &amp;&amp; p) {

          _wDS(<span class="string">'localFail'</span>, <span class="number">2</span>);

          <span class="keyword">if</span> (!sm2.debugFlash) {
            _wDS(<span class="string">'tryDebug'</span>, <span class="number">2</span>);
          }

        }

        <span class="keyword">if</span> (p === <span class="number">0</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-429">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-429">&#182;</a>
              </div>
              <p>if 0 (not null), probably a 404.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2._wD(str(<span class="string">'swf404'</span>, sm2.url), <span class="number">1</span>);

        }

        debugTS(<span class="string">'flashtojs'</span>, <span class="literal">false</span>, <span class="string">': Timed out'</span> + (overHTTP ? <span class="string">' (Check flash security or flash blockers)'</span> : <span class="string">' (No plugin/missing SWF?)'</span>));

      }</pre></div></div>
            
        </li>
        
        
        <li id="section-430">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-430">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
        </li>
        
        
        <li id="section-431">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-431">&#182;</a>
              </div>
              <p>give up / time-out, depending</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
      <span class="keyword">if</span> (!didInit &amp;&amp; okToDisable) {

        <span class="keyword">if</span> (p === <span class="literal">null</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-432">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-432">&#182;</a>
              </div>
              <p>SWF failed to report load progress. Possibly blocked.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          <span class="keyword">if</span> (sm2.useFlashBlock || sm2.flashLoadTimeout === <span class="number">0</span>) {

            <span class="keyword">if</span> (sm2.useFlashBlock) {

              flashBlockHandler();

            }

            _wDS(<span class="string">'waitForever'</span>);

          } <span class="keyword">else</span> <span class="keyword">if</span> (!sm2.useFlashBlock &amp;&amp; canIgnoreFlash) {</pre></div></div>
            
        </li>
        
        
        <li id="section-433">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-433">&#182;</a>
              </div>
              <p>no custom flash block handling, but SWF has timed out. Will recover if user unblocks / allows SWF load.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            rebootIntoHTML5();

          } <span class="keyword">else</span> {

            _wDS(<span class="string">'waitForever'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-434">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-434">&#182;</a>
              </div>
              <p>fire any regular registered ontimeout() listeners.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>            processOnEvents({
              type: <span class="string">'ontimeout'</span>,
              ignoreInit: <span class="literal">true</span>,
              error: {
                type: <span class="string">'INIT_FLASHBLOCK'</span>
              }
            });

          }

        } <span class="keyword">else</span> <span class="keyword">if</span> (sm2.flashLoadTimeout === <span class="number">0</span>) {</pre></div></div>
            
        </li>
        
        
        <li id="section-435">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-435">&#182;</a>
              </div>
              <p>SWF loaded? Shouldn&#39;t be a blocking issue, then.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
          _wDS(<span class="string">'waitForever'</span>);

        } <span class="keyword">else</span> <span class="keyword">if</span> (!sm2.useFlashBlock &amp;&amp; canIgnoreFlash) {

          rebootIntoHTML5();

        } <span class="keyword">else</span> {

          failSafely(<span class="literal">true</span>);

        }

      }

    }, sm2.flashLoadTimeout);

  };

  handleFocus = <span class="keyword">function</span>() {

    <span class="function"><span class="keyword">function</span> <span class="title">cleanup</span><span class="params">()</span> {</span>
      event.remove(window, <span class="string">'focus'</span>, handleFocus);
    }

    <span class="keyword">if</span> (isFocused || !tryInitOnFocus) {</pre></div></div>
            
        </li>
        
        
        <li id="section-436">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-436">&#182;</a>
              </div>
              <p>already focused, or not special Safari background tab case</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      cleanup();
      <span class="keyword">return</span> <span class="literal">true</span>;
    }

    okToDisable = <span class="literal">true</span>;
    isFocused = <span class="literal">true</span>;
    _wDS(<span class="string">'gotFocus'</span>);</pre></div></div>
            
        </li>
        
        
        <li id="section-437">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-437">&#182;</a>
              </div>
              <p>allow init to restart</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    waitingForEI = <span class="literal">false</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-438">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-438">&#182;</a>
              </div>
              <p>kick off ExternalInterface timeout, now that the SWF has started</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    delayWaitForEI();

    cleanup();
    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  flushMessages = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-439">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-439">&#182;</a>
              </div>
              <d>

            </div>
            
        </li>
        
        
        <li id="section-440">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-440">&#182;</a>
              </div>
              <p>SM2 pre-init debug messages</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    <span class="keyword">if</span> (messages.length) {
      sm2._wD(<span class="string">'SoundManager 2: '</span> + messages.join(<span class="string">' '</span>), <span class="number">1</span>);
      messages = [];
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-441">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-441">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  showSupport = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-442">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-442">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    flushMessages();

    <span class="keyword">var</span> item, tests = [];

    <span class="keyword">if</span> (sm2.useHTML5Audio &amp;&amp; sm2.hasHTML5) {
      <span class="keyword">for</span> (item <span class="keyword">in</span> sm2.audioFormats) {
        <span class="keyword">if</span> (sm2.audioFormats.hasOwnProperty(item)) {
          tests.push(item + <span class="string">' = '</span> + sm2.html5[item] + (!sm2.html5[item] &amp;&amp; needsFlash &amp;&amp; sm2.flash[item] ? <span class="string">' (using flash)'</span> : (sm2.preferFlash &amp;&amp; sm2.flash[item] &amp;&amp; needsFlash ? <span class="string">' (preferring flash)'</span> : (!sm2.html5[item] ? <span class="string">' ('</span> + (sm2.audioFormats[item].required ? <span class="string">'required, '</span> : <span class="string">''</span>) + <span class="string">'and no flash support)'</span> : <span class="string">''</span>))));
        }
      }
      sm2._wD(<span class="string">'SoundManager 2 HTML5 support: '</span> + tests.join(<span class="string">', '</span>), <span class="number">1</span>);
    }</pre></div></div>
            
        </li>
        
        
        <li id="section-443">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-443">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
  };

  initComplete = <span class="keyword">function</span>(bNoDisable) {

    <span class="keyword">if</span> (didInit) <span class="keyword">return</span> <span class="literal">false</span>;

    <span class="keyword">if</span> (sm2.html5Only) {</pre></div></div>
            
        </li>
        
        
        <li id="section-444">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-444">&#182;</a>
              </div>
              <p>all good.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      _wDS(<span class="string">'sm2Loaded'</span>, <span class="number">1</span>);
      didInit = <span class="literal">true</span>;
      initUserOnload();
      debugTS(<span class="string">'onload'</span>, <span class="literal">true</span>);
      <span class="keyword">return</span> <span class="literal">true</span>;
    }

    <span class="keyword">var</span> wasTimeout = (sm2.useFlashBlock &amp;&amp; sm2.flashLoadTimeout &amp;&amp; !sm2.getMoviePercent()),
        result = <span class="literal">true</span>,
        error;

    <span class="keyword">if</span> (!wasTimeout) {
      didInit = <span class="literal">true</span>;
    }

    error = {
      type: (!hasFlash &amp;&amp; needsFlash ? <span class="string">'NO_FLASH'</span> : <span class="string">'INIT_TIMEOUT'</span>)
    };

    sm2._wD(<span class="string">'SoundManager 2 '</span> + (disabled ? <span class="string">'failed to load'</span> : <span class="string">'loaded'</span>) + <span class="string">' ('</span> + (disabled ? <span class="string">'Flash security/load error'</span> : <span class="string">'OK'</span>) + <span class="string">') '</span> + String.fromCharCode(disabled ? <span class="number">10006</span> : <span class="number">10003</span>), disabled ? <span class="number">2</span> : <span class="number">1</span>);

    <span class="keyword">if</span> (disabled || bNoDisable) {

      <span class="keyword">if</span> (sm2.useFlashBlock &amp;&amp; sm2.oMC) {
        sm2.oMC.className = getSWFCSS() + <span class="string">' '</span> + (sm2.getMoviePercent() === <span class="literal">null</span> ? swfCSS.swfTimedout : swfCSS.swfError);
      }

      processOnEvents({
        type: <span class="string">'ontimeout'</span>,
        error: error,
        ignoreInit: <span class="literal">true</span>
      });

      debugTS(<span class="string">'onload'</span>, <span class="literal">false</span>);
      catchError(error);

      result = <span class="literal">false</span>;

    } <span class="keyword">else</span> {

      debugTS(<span class="string">'onload'</span>, <span class="literal">true</span>);

    }

    <span class="keyword">if</span> (!disabled) {

      <span class="keyword">if</span> (sm2.waitForWindowLoad &amp;&amp; !windowLoaded) {

        _wDS(<span class="string">'waitOnload'</span>);
        event.add(window, <span class="string">'load'</span>, initUserOnload);

      } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-445">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-445">&#182;</a>
              </div>
              <d>

            </div>
            
            <div class="content"><div class='highlight'><pre>        <span class="keyword">if</span> (sm2.waitForWindowLoad &amp;&amp; windowLoaded) {
          _wDS(<span class="string">'docLoaded'</span>);
        }</pre></div></div>
            
        </li>
        
        
        <li id="section-446">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-446">&#182;</a>
              </div>
              <p></d></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        initUserOnload();

      }

    }

    <span class="keyword">return</span> result;

  };

  <span class="comment">/**
   * apply top-level setupOptions object as local properties, eg., this.setupOptions.flashVersion -&gt; this.flashVersion (soundManager.flashVersion)
   * this maintains backward compatibility, and allows properties to be defined separately for use by soundManager.setup().
   */</span>

  setProperties = <span class="keyword">function</span>() {

    <span class="keyword">var</span> i,
        o = sm2.setupOptions;

    <span class="keyword">for</span> (i <span class="keyword">in</span> o) {

      <span class="keyword">if</span> (o.hasOwnProperty(i)) {</pre></div></div>
            
        </li>
        
        
        <li id="section-447">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-447">&#182;</a>
              </div>
              <p>assign local property if not already defined</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
        <span class="keyword">if</span> (sm2[i] === _<span class="literal">undefined</span>) {

          sm2[i] = o[i];

        } <span class="keyword">else</span> <span class="keyword">if</span> (sm2[i] !== o[i]) {</pre></div></div>
            
        </li>
        
        
        <li id="section-448">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-448">&#182;</a>
              </div>
              <p>legacy support: write manually-assigned property (eg., soundManager.url) back to setupOptions to keep things in sync</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>          sm2.setupOptions[i] = sm2[i];

        }

      }

    }

  };


  init = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-449">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-449">&#182;</a>
              </div>
              <p>called after onload()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
    <span class="keyword">if</span> (didInit) {
      _wDS(<span class="string">'didInit'</span>);
      <span class="keyword">return</span> <span class="literal">false</span>;
    }

    <span class="function"><span class="keyword">function</span> <span class="title">cleanup</span><span class="params">()</span> {</span>
      event.remove(window, <span class="string">'load'</span>, sm2.beginDelayedInit);
    }

    <span class="keyword">if</span> (sm2.html5Only) {

      <span class="keyword">if</span> (!didInit) {</pre></div></div>
            
        </li>
        
        
        <li id="section-450">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-450">&#182;</a>
              </div>
              <p>we don&#39;t need no steenking flash!</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        cleanup();
        sm2.enabled = <span class="literal">true</span>;
        initComplete();
      }

      <span class="keyword">return</span> <span class="literal">true</span>;

    }</pre></div></div>
            
        </li>
        
        
        <li id="section-451">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-451">&#182;</a>
              </div>
              <p>flash path</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    initMovie();

    <span class="keyword">try</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-452">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-452">&#182;</a>
              </div>
              <p>attempt to talk to Flash</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      flash._externalInterfaceTest(<span class="literal">false</span>);

      <span class="comment">/**
       * Apply user-specified polling interval, OR, if "high performance" set, faster vs. default polling
       * (determines frequency of whileloading/whileplaying callbacks, effectively driving UI framerates)
       */</span>
      setPolling(<span class="literal">true</span>, (sm2.flashPollingInterval || (sm2.useHighPerformance ? <span class="number">10</span> : <span class="number">50</span>)));

      <span class="keyword">if</span> (!sm2.debugMode) {</pre></div></div>
            
        </li>
        
        
        <li id="section-453">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-453">&#182;</a>
              </div>
              <p>stop the SWF from making debug output calls to JS</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        flash._disableDebug();
      }

      sm2.enabled = <span class="literal">true</span>;
      debugTS(<span class="string">'jstoflash'</span>, <span class="literal">true</span>);

      <span class="keyword">if</span> (!sm2.html5Only) {</pre></div></div>
            
        </li>
        
        
        <li id="section-454">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-454">&#182;</a>
              </div>
              <p>prevent browser from showing cached page state (or rather, restoring &quot;suspended&quot; page state) via back button, because flash may be dead
<a href="http://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/">http://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        event.add(window, <span class="string">'unload'</span>, doNothing);
      }

    } <span class="keyword">catch</span>(e) {

      sm2._wD(<span class="string">'js/flash exception: '</span> + e.toString());

      debugTS(<span class="string">'jstoflash'</span>, <span class="literal">false</span>);

      catchError({
        type: <span class="string">'JS_TO_FLASH_EXCEPTION'</span>,
        fatal: <span class="literal">true</span>
      });</pre></div></div>
            
        </li>
        
        
        <li id="section-455">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-455">&#182;</a>
              </div>
              <p>don&#39;t disable, for reboot()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      failSafely(<span class="literal">true</span>);

      initComplete();

      <span class="keyword">return</span> <span class="literal">false</span>;

    }

    initComplete();</pre></div></div>
            
        </li>
        
        
        <li id="section-456">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-456">&#182;</a>
              </div>
              <p>disconnect events</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    cleanup();

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  domContentLoaded = <span class="keyword">function</span>() {

    <span class="keyword">if</span> (didDCLoaded) <span class="keyword">return</span> <span class="literal">false</span>;

    didDCLoaded = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-457">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-457">&#182;</a>
              </div>
              <p>assign top-level soundManager properties eg. soundManager.url</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    setProperties();

    initDebug();

    <span class="keyword">if</span> (!hasFlash &amp;&amp; sm2.hasHTML5) {

      sm2._wD(<span class="string">'SoundManager 2: No Flash detected'</span> + (!sm2.useHTML5Audio ? <span class="string">', enabling HTML5.'</span> : <span class="string">'. Trying HTML5-only mode.'</span>), <span class="number">1</span>);

      sm2.setup({
        useHTML5Audio: <span class="literal">true</span>,</pre></div></div>
            
        </li>
        
        
        <li id="section-458">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-458">&#182;</a>
              </div>
              <p>make sure we aren&#39;t preferring flash, either
TODO: preferFlash should not matter if flash is not installed. Currently, stuff breaks without the below tweak.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>        preferFlash: <span class="literal">false</span>
      });

    }

    testHTML5();

    <span class="keyword">if</span> (!hasFlash &amp;&amp; needsFlash) {

      messages.push(strings.needFlash);</pre></div></div>
            
        </li>
        
        
        <li id="section-459">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-459">&#182;</a>
              </div>
              <p>TODO: Fatal here vs. timeout approach, etc.
hack: fail sooner.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>      sm2.setup({
        flashLoadTimeout: <span class="number">1</span>
      });

    }

    <span class="keyword">if</span> (doc.removeEventListener) {
      doc.removeEventListener(<span class="string">'DOMContentLoaded'</span>, domContentLoaded, <span class="literal">false</span>);
    }

    initMovie();

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  domContentLoadedIE = <span class="keyword">function</span>() {

    <span class="keyword">if</span> (doc.readyState === <span class="string">'complete'</span>) {
      domContentLoaded();
      doc.detachEvent(<span class="string">'onreadystatechange'</span>, domContentLoadedIE);
    }

    <span class="keyword">return</span> <span class="literal">true</span>;

  };

  winOnLoad = <span class="keyword">function</span>() {</pre></div></div>
            
        </li>
        
        
        <li id="section-460">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-460">&#182;</a>
              </div>
              <p>catch edge case of initComplete() firing after window.load()</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    windowLoaded = <span class="literal">true</span>;</pre></div></div>
            
        </li>
        
        
        <li id="section-461">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-461">&#182;</a>
              </div>
              <p>catch case where DOMContentLoaded has been sent, but we&#39;re still in doc.readyState = &#39;interactive&#39;</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    domContentLoaded();

    event.remove(window, <span class="string">'load'</span>, winOnLoad);

  };</pre></div></div>
            
        </li>
        
        
        <li id="section-462">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-462">&#182;</a>
              </div>
              <p>sniff up-front</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  detectFlash();</pre></div></div>
            
        </li>
        
        
        <li id="section-463">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-463">&#182;</a>
              </div>
              <p>focus and window load, init (primarily flash-driven)</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  event.add(window, <span class="string">'focus'</span>, handleFocus);
  event.add(window, <span class="string">'load'</span>, delayWaitForEI);
  event.add(window, <span class="string">'load'</span>, winOnLoad);

  <span class="keyword">if</span> (doc.addEventListener) {

    doc.addEventListener(<span class="string">'DOMContentLoaded'</span>, domContentLoaded, <span class="literal">false</span>);

  } <span class="keyword">else</span> <span class="keyword">if</span> (doc.attachEvent) {

    doc.attachEvent(<span class="string">'onreadystatechange'</span>, domContentLoadedIE);

  } <span class="keyword">else</span> {</pre></div></div>
            
        </li>
        
        
        <li id="section-464">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-464">&#182;</a>
              </div>
              <p>no add/attachevent support - safe to assume no JS -&gt; Flash either</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    debugTS(<span class="string">'onload'</span>, <span class="literal">false</span>);
    catchError({
      type: <span class="string">'NO_DOM2_EVENTS'</span>,
      fatal: <span class="literal">true</span>
    });

  }

} <span class="comment">// SoundManager()</span></pre></div></div>
            
        </li>
        
        
        <li id="section-465">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-465">&#182;</a>
              </div>
              <p>SM2_DEFER details: <a href="http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading">http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading</a></p>

            </div>
            
            <div class="content"><div class='highlight'><pre>
<span class="keyword">if</span> (window.SM2_DEFER === _<span class="literal">undefined</span> || !SM2_DEFER) {
  soundManager = <span class="keyword">new</span> SoundManager();
}

<span class="comment">/**
 * SoundManager public interfaces
 * ------------------------------
 */</span>

<span class="keyword">if</span> (<span class="keyword">typeof</span> module === <span class="string">'object'</span> &amp;&amp; module &amp;&amp; <span class="keyword">typeof</span> module.exports === <span class="string">'object'</span>) {

  <span class="comment">/**
   * commonJS module
   */</span>

  module.exports.SoundManager = SoundManager;
  module.exports.soundManager = soundManager;

} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> define === <span class="string">'function'</span> &amp;&amp; define.amd) {

  <span class="comment">/**
   * AMD - requireJS
   * basic usage:
   * require(["/path/to/soundmanager2.js"], function(SoundManager) {
   *   SoundManager.getInstance().setup({
   *     url: '/swf/',
   *     onready: function() { ... }
   *   })
   * });
   *
   * SM2_DEFER usage:
   * window.SM2_DEFER = true;
   * require(["/path/to/soundmanager2.js"], function(SoundManager) {
   *   SoundManager.getInstance(function() {
   *     var soundManager = new SoundManager.constructor();
   *     soundManager.setup({
   *       url: '/swf/',
   *       ...
   *     });
   *     ...
   *     soundManager.beginDelayedInit();
   *     return soundManager;
   *   })
   * });
   */</span>

  define(<span class="keyword">function</span>() {
    <span class="comment">/**
     * Retrieve the global instance of SoundManager.
     * If a global instance does not exist it can be created using a callback.
     *
     * @param {Function} smBuilder Optional: Callback used to create a new SoundManager instance
     * @return {SoundManager} The global SoundManager instance
     */</span>
    <span class="function"><span class="keyword">function</span> <span class="title">getInstance</span><span class="params">(smBuilder)</span> {</span>
      <span class="keyword">if</span> (!window.soundManager &amp;&amp; smBuilder <span class="keyword">instanceof</span> Function) {
        <span class="keyword">var</span> instance = smBuilder(SoundManager);
        <span class="keyword">if</span> (instance <span class="keyword">instanceof</span> SoundManager) {
          window.soundManager = instance;
        }
      }
      <span class="keyword">return</span> window.soundManager;
    }
    <span class="keyword">return</span> {
      constructor: SoundManager,
      getInstance: getInstance
    };
  });

}</pre></div></div>
            
        </li>
        
        
        <li id="section-466">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-466">&#182;</a>
              </div>
              <p>standard browser case</p>

            </div>
            
        </li>
        
        
        <li id="section-467">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-467">&#182;</a>
              </div>
              <p>constructor</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>window.SoundManager = SoundManager;

<span class="comment">/**
 * note: SM2 requires a window global due to Flash, which makes calls to window.soundManager.
 * Flash may not always be needed, but this is not known until async init and SM2 may even "reboot" into Flash mode.
 */</span></pre></div></div>
            
        </li>
        
        
        <li id="section-468">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-468">&#182;</a>
              </div>
              <p>public API, flash callbacks etc.</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>window.soundManager = soundManager;

}(window));</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
